https://launchpad.net/ubuntu/+archive/test-rebuild-20211217-jammy-gcc12/+build/22760933 RUN: /usr/share/launchpad-buildd/bin/builder-prep Kernel version: Linux lcy02-amd64-032 4.15.0-166-generic #174-Ubuntu SMP Wed Dec 8 19:07:44 UTC 2021 x86_64 Buildd toolchain package versions: launchpad-buildd_205~511~ubuntu18.04.1 python3-lpbuildd_205~511~ubuntu18.04.1 sbuild_0.75.0-1ubuntu1 bzr-builder_0.7.3+bzr174~ppa13~ubuntu16.04.1 bzr_2.7.0+bzr6622-10 git-build-recipe_0.3.6~git201906051340.ff11471~ubuntu18.04.1 git_1:2.17.1-1ubuntu0.9 dpkg-dev_1.19.0.5ubuntu2.3 python-debian_0.1.32 python3-debian_0.1.32. Syncing the system clock with the buildd NTP service... 11 Jan 01:18:24 ntpdate[1757]: adjust time server 10.131.248.1 offset 0.000878 sec RUN: /usr/share/launchpad-buildd/bin/in-target unpack-chroot --backend=chroot --series=jammy --arch=amd64 PACKAGEBUILD-22760933 --image-type chroot /home/buildd/filecache-default/b0c128df17a460089eca69348f06144377489985 Creating target for build PACKAGEBUILD-22760933 RUN: /usr/share/launchpad-buildd/bin/in-target mount-chroot --backend=chroot --series=jammy --arch=amd64 PACKAGEBUILD-22760933 Starting target for build PACKAGEBUILD-22760933 RUN: /usr/share/launchpad-buildd/bin/in-target override-sources-list --backend=chroot --series=jammy --arch=amd64 PACKAGEBUILD-22760933 'deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy main' 'deb http://ppa.launchpad.net/ubuntu-toolchain-r/volatile/ubuntu jammy main' 'deb http://ftpmaster.internal/ubuntu jammy main restricted universe multiverse' Overriding sources.list in build-PACKAGEBUILD-22760933 RUN: /usr/share/launchpad-buildd/bin/in-target add-trusted-keys --backend=chroot --series=jammy --arch=amd64 PACKAGEBUILD-22760933 Adding trusted keys to build-PACKAGEBUILD-22760933 Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). OK Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). /etc/apt/trusted.gpg -------------------- pub rsa1024 2009-10-22 [SC] 60C3 1780 3A41 BA51 845E 371A 1E93 77A2 BA9E F27F uid [ unknown] Launchpad Toolchain builds /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg ------------------------------------------------------ pub rsa4096 2012-05-11 [SC] 8439 38DF 228D 22F7 B374 2BC0 D94A A3F0 EFE2 1092 uid [ unknown] Ubuntu CD Image Automatic Signing Key (2012) /etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg ------------------------------------------------------ pub rsa4096 2018-09-17 [SC] F6EC B376 2474 EDA9 D21B 7022 8719 20D1 991B C93C uid [ unknown] Ubuntu Archive Automatic Signing Key (2018) RUN: /usr/share/launchpad-buildd/bin/in-target update-debian-chroot --backend=chroot --series=jammy --arch=amd64 PACKAGEBUILD-22760933 Updating target for build PACKAGEBUILD-22760933 Get:1 http://ftpmaster.internal/ubuntu jammy InRelease [270 kB] Get:2 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy InRelease [23.8 kB] Get:3 http://ppa.launchpad.net/ubuntu-toolchain-r/volatile/ubuntu jammy InRelease [23.8 kB] Get:4 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 Packages [15.1 kB] Get:5 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main Translation-en [7676 B] Get:6 http://ppa.launchpad.net/ubuntu-toolchain-r/volatile/ubuntu jammy/main amd64 Packages [15.7 kB] Get:7 http://ppa.launchpad.net/ubuntu-toolchain-r/volatile/ubuntu jammy/main Translation-en [5972 B] Get:8 http://ftpmaster.internal/ubuntu jammy/main amd64 Packages [1407 kB] Get:9 http://ftpmaster.internal/ubuntu jammy/main Translation-en [514 kB] Get:10 http://ftpmaster.internal/ubuntu jammy/restricted amd64 Packages [93.8 kB] Get:11 http://ftpmaster.internal/ubuntu jammy/restricted Translation-en [13.3 kB] Get:12 http://ftpmaster.internal/ubuntu jammy/universe amd64 Packages [13.8 MB] Get:13 http://ftpmaster.internal/ubuntu jammy/universe Translation-en [5593 kB] Get:14 http://ftpmaster.internal/ubuntu jammy/multiverse amd64 Packages [216 kB] Get:15 http://ftpmaster.internal/ubuntu jammy/multiverse Translation-en [111 kB] Fetched 22.1 MB in 2s (9217 kB/s) Reading package lists... Reading package lists... Building dependency tree... Reading state information... Calculating upgrade... The following package was automatically installed and is no longer required: libssl1.1 Use 'sudo apt autoremove' to remove it. The following packages will be REMOVED: libsemanage1* The following NEW packages will be installed: gcc-12-base libexpat1 libmpdec3 libpython3-stdlib libpython3.9-minimal libpython3.9-stdlib libsemanage2 libsepol2 libssl3 media-types python3 python3-minimal python3-psutil python3.9 python3.9-minimal The following packages have been kept back: cpp g++ gcc The following packages will be upgraded: apt base-files bash binutils binutils-common binutils-x86-64-linux-gnu bsdutils bzip2 ca-certificates cpp-11 dash debconf debianutils dpkg dpkg-dev e2fsprogs g++-11 gcc-11 gcc-11-base gpg gpg-agent gpgconf gpgv grep init init-system-helpers libapparmor1 libapt-pkg6.0 libasan6 libatomic1 libattr1 libbinutils libblkid1 libbz2-1.0 libcc1-0 libcom-err2 libcrypt-dev libcrypt1 libcryptsetup12 libctf-nobfd0 libctf0 libdpkg-perl libext2fs2 libgcc-11-dev libgcc-s1 libgcrypt20 libgdbm-compat4 libgdbm6 libgnutls30 libgomp1 libgpg-error0 libgssapi-krb5-2 libidn2-0 libip4tc2 libisl23 libitm1 libk5crypto3 libkmod2 libkrb5-3 libkrb5support0 liblsan0 libmount1 libmpc3 libncurses6 libncursesw6 libp11-kit0 libpam-modules libpam-modules-bin libpam-runtime libpam0g libpcre2-8-0 libquadmath0 libreadline8 libseccomp2 libselinux1 libsemanage-common libsmartcols1 libsqlite3-0 libss2 libstdc++-11-dev libstdc++6 libsystemd0 libtasn1-6 libtinfo6 libtsan0 libubsan1 libudev1 libuuid1 libzstd1 lockfile-progs login logsave lto-disabled-list make mount ncurses-base ncurses-bin openssl passwd pkgbinarymangler readline-common sed sensible-utils systemd systemd-sysv systemd-timesyncd tzdata usrmerge util-linux 109 upgraded, 15 newly installed, 1 to remove and 3 not upgraded. Need to get 88.9 MB of archives. After this operation, 332 MB disk space will be freed. Get:1 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 gcc-12-base amd64 12-20220106-1ubuntu1 [19.5 kB] Get:2 http://ftpmaster.internal/ubuntu jammy/main amd64 debconf all 1.5.79 [126 kB] Get:3 http://ftpmaster.internal/ubuntu jammy/main amd64 libpam0g amd64 1.4.0-10ubuntu2 [61.5 kB] Get:4 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 libgcc-s1 amd64 12-20220106-1ubuntu1 [54.9 kB] Get:5 http://ftpmaster.internal/ubuntu jammy/main amd64 libcrypt-dev amd64 1:4.4.27-1 [112 kB] Get:6 http://ftpmaster.internal/ubuntu jammy/main amd64 libcrypt1 amd64 1:4.4.27-1 [82.0 kB] Get:7 http://ftpmaster.internal/ubuntu jammy/main amd64 base-files amd64 12ubuntu2 [63.3 kB] Get:8 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 libstdc++6 amd64 12-20220106-1ubuntu1 [664 kB] Get:9 http://ftpmaster.internal/ubuntu jammy/main amd64 debianutils amd64 5.5-1ubuntu1 [107 kB] Get:10 http://ftpmaster.internal/ubuntu jammy/main amd64 bash amd64 5.1-6ubuntu1 [769 kB] Get:11 http://ftpmaster.internal/ubuntu jammy/main amd64 bsdutils amd64 1:2.37.2-4ubuntu1 [80.9 kB] Get:12 http://ppa.launchpad.net/ubuntu-toolchain-r/volatile/ubuntu jammy/main amd64 dpkg amd64 1.21.1ubuntu11 [1254 kB] Get:13 http://ftpmaster.internal/ubuntu jammy/main amd64 libgpg-error0 amd64 1.43-1 [69.6 kB] Get:14 http://ftpmaster.internal/ubuntu jammy/main amd64 libgcrypt20 amd64 1.9.4-3ubuntu2 [515 kB] Get:15 http://ftpmaster.internal/ubuntu jammy/main amd64 bzip2 amd64 1.0.8-5 [34.8 kB] Get:16 http://ftpmaster.internal/ubuntu jammy/main amd64 libbz2-1.0 amd64 1.0.8-5 [34.5 kB] Get:17 http://ftpmaster.internal/ubuntu jammy/main amd64 libssl3 amd64 3.0.0-1ubuntu1 [1896 kB] Get:18 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 libgomp1 amd64 12-20220106-1ubuntu1 [127 kB] Get:19 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 libitm1 amd64 12-20220106-1ubuntu1 [30.0 kB] Get:20 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 libatomic1 amd64 12-20220106-1ubuntu1 [10.1 kB] Get:21 http://ftpmaster.internal/ubuntu jammy/main amd64 libblkid1 amd64 2.37.2-4ubuntu1 [103 kB] Get:22 http://ftpmaster.internal/ubuntu jammy/main amd64 libuuid1 amd64 2.37.2-4ubuntu1 [23.8 kB] Get:23 http://ftpmaster.internal/ubuntu jammy/main amd64 libcryptsetup12 amd64 2:2.4.2-1ubuntu4 [208 kB] Get:24 http://ftpmaster.internal/ubuntu jammy/main amd64 libidn2-0 amd64 2.3.2-2 [66.5 kB] Get:25 http://ftpmaster.internal/ubuntu jammy/main amd64 libp11-kit0 amd64 0.24.0-6 [252 kB] Get:26 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 liblsan0 amd64 12-20220106-1ubuntu1 [1068 kB] Get:27 http://ftpmaster.internal/ubuntu jammy/main amd64 libtasn1-6 amd64 4.18.0-4 [42.9 kB] Get:28 http://ftpmaster.internal/ubuntu jammy/main amd64 libgnutls30 amd64 3.7.2-4ubuntu1 [956 kB] Get:29 http://ftpmaster.internal/ubuntu jammy/main amd64 systemd-sysv amd64 249.5-2ubuntu3 [10.5 kB] Get:30 http://ftpmaster.internal/ubuntu jammy/main amd64 systemd-timesyncd amd64 249.5-2ubuntu3 [30.9 kB] Get:31 http://ftpmaster.internal/ubuntu jammy/main amd64 libapparmor1 amd64 3.0.3-0ubuntu5 [38.0 kB] Get:32 http://ftpmaster.internal/ubuntu jammy/main amd64 libip4tc2 amd64 1.8.7-1ubuntu4 [19.8 kB] Get:33 http://ftpmaster.internal/ubuntu jammy/main amd64 libzstd1 amd64 1.4.8+dfsg-3 [324 kB] Get:34 http://ftpmaster.internal/ubuntu jammy/main amd64 libkmod2 amd64 28-1ubuntu5 [48.0 kB] Get:35 http://ftpmaster.internal/ubuntu jammy/main amd64 libpcre2-8-0 amd64 10.39-3 [220 kB] Get:36 http://ftpmaster.internal/ubuntu jammy/main amd64 libselinux1 amd64 3.3-1 [74.6 kB] Get:37 http://ftpmaster.internal/ubuntu jammy/main amd64 libmount1 amd64 2.37.2-4ubuntu1 [122 kB] Get:38 http://ftpmaster.internal/ubuntu jammy/main amd64 libseccomp2 amd64 2.5.2-2ubuntu2 [48.3 kB] Get:39 http://ftpmaster.internal/ubuntu jammy/main amd64 login amd64 1:4.8.1-2ubuntu1 [188 kB] Get:40 http://ftpmaster.internal/ubuntu jammy/main amd64 util-linux amd64 2.37.2-4ubuntu1 [1063 kB] Get:41 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 libubsan1 amd64 12-20220106-1ubuntu1 [974 kB] Get:42 http://ftpmaster.internal/ubuntu jammy/main amd64 mount amd64 2.37.2-4ubuntu1 [114 kB] Get:43 http://ftpmaster.internal/ubuntu jammy/main amd64 systemd amd64 249.5-2ubuntu3 [4542 kB] Get:44 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 libquadmath0 amd64 12-20220106-1ubuntu1 [154 kB] Get:45 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu jammy/main amd64 libcc1-0 amd64 12-20220106-1ubuntu1 [46.7 kB] Get:46 http://ppa.launchpad.net/ubuntu-toolchain-r/volatile/ubuntu jammy/main amd64 dpkg-dev all 1.21.1ubuntu11 [926 kB] Get:47 http://ftpmaster.internal/ubuntu jammy/main amd64 libsystemd0 amd64 249.5-2ubuntu3 [318 kB] Get:48 http://ftpmaster.internal/ubuntu jammy/main amd64 libudev1 amd64 249.5-2ubuntu3 [77.9 kB] Get:49 http://ftpmaster.internal/ubuntu jammy/main amd64 libapt-pkg6.0 amd64 2.3.14 [905 kB] Get:50 http://ftpmaster.internal/ubuntu jammy/main amd64 dash amd64 0.5.11+git20210903+057cd650a4ed-3 [91.8 kB] Get:51 http://ftpmaster.internal/ubuntu jammy/main amd64 grep amd64 3.7-1 [156 kB] Get:52 http://ftpmaster.internal/ubuntu jammy/main amd64 libncurses6 amd64 6.3-1 [111 kB] Get:53 http://ftpmaster.internal/ubuntu jammy/main amd64 libncursesw6 amd64 6.3-1 [147 kB] Get:54 http://ftpmaster.internal/ubuntu jammy/main amd64 libtinfo6 amd64 6.3-1 [104 kB] Get:55 http://ppa.launchpad.net/ubuntu-toolchain-r/volatile/ubuntu jammy/main amd64 libdpkg-perl all 1.21.1ubuntu11 [236 kB] Get:56 http://ftpmaster.internal/ubuntu jammy/main amd64 ncurses-bin amd64 6.3-1 [184 kB] Get:57 http://ftpmaster.internal/ubuntu jammy/main amd64 sed amd64 4.8-1ubuntu1 [188 kB] Get:58 http://ftpmaster.internal/ubuntu jammy/main amd64 init-system-helpers all 1.61 [39.3 kB] Get:59 http://ftpmaster.internal/ubuntu jammy/main amd64 ncurses-base all 6.3-1 [19.9 kB] Get:60 http://ftpmaster.internal/ubuntu jammy/main amd64 gpgv amd64 2.2.27-3ubuntu1 [137 kB] Get:61 http://ftpmaster.internal/ubuntu jammy/main amd64 apt amd64 2.3.14 [1387 kB] Get:62 http://ftpmaster.internal/ubuntu jammy/main amd64 libsepol2 amd64 3.3-1 [281 kB] Get:63 http://ftpmaster.internal/ubuntu jammy/main amd64 libsemanage-common all 3.3-1 [10.1 kB] Get:64 http://ftpmaster.internal/ubuntu jammy/main amd64 libsemanage2 amd64 3.3-1 [92.5 kB] Get:65 http://ftpmaster.internal/ubuntu jammy/main amd64 passwd amd64 1:4.8.1-2ubuntu1 [765 kB] Get:66 http://ftpmaster.internal/ubuntu jammy/main amd64 libpam-modules-bin amd64 1.4.0-10ubuntu2 [37.6 kB] Get:67 http://ftpmaster.internal/ubuntu jammy/main amd64 libpam-modules amd64 1.4.0-10ubuntu2 [280 kB] Get:68 http://ftpmaster.internal/ubuntu jammy/main amd64 logsave amd64 1.46.5-1ubuntu1 [10.9 kB] Get:69 http://ftpmaster.internal/ubuntu jammy/main amd64 libext2fs2 amd64 1.46.5-1ubuntu1 [209 kB] Get:70 http://ftpmaster.internal/ubuntu jammy/main amd64 e2fsprogs amd64 1.46.5-1ubuntu1 [590 kB] Get:71 http://ftpmaster.internal/ubuntu jammy/main amd64 init amd64 1.61 [6102 B] Get:72 http://ftpmaster.internal/ubuntu jammy/main amd64 libpython3.9-minimal amd64 3.9.9-2 [790 kB] Get:73 http://ftpmaster.internal/ubuntu jammy/main amd64 libexpat1 amd64 2.4.2-1 [90.1 kB] Get:74 http://ftpmaster.internal/ubuntu jammy/main amd64 python3.9-minimal amd64 3.9.9-2 [2062 kB] Get:75 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-minimal amd64 3.9.7-4 [24.7 kB] Get:76 http://ftpmaster.internal/ubuntu jammy/main amd64 media-types all 4.0.0 [22.2 kB] Get:77 http://ftpmaster.internal/ubuntu jammy/main amd64 tzdata all 2021e-1ubuntu1 [343 kB] Get:78 http://ftpmaster.internal/ubuntu jammy/main amd64 libmpdec3 amd64 2.5.1-2build1 [86.8 kB] Get:79 http://ftpmaster.internal/ubuntu jammy/main amd64 readline-common all 8.1.2-1 [53.5 kB] Get:80 http://ftpmaster.internal/ubuntu jammy/main amd64 libreadline8 amd64 8.1.2-1 [153 kB] Get:81 http://ftpmaster.internal/ubuntu jammy/main amd64 libsqlite3-0 amd64 3.36.0-2 [641 kB] Get:82 http://ftpmaster.internal/ubuntu jammy/main amd64 libpython3.9-stdlib amd64 3.9.9-2 [1807 kB] Get:83 http://ftpmaster.internal/ubuntu jammy/main amd64 python3.9 amd64 3.9.9-2 [437 kB] Get:84 http://ftpmaster.internal/ubuntu jammy/main amd64 libpython3-stdlib amd64 3.9.7-4 [7298 B] Get:85 http://ftpmaster.internal/ubuntu jammy/main amd64 python3 amd64 3.9.7-4 [22.8 kB] Get:86 http://ftpmaster.internal/ubuntu jammy/main amd64 libattr1 amd64 1:2.5.1-1 [13.3 kB] Get:87 http://ftpmaster.internal/ubuntu jammy/main amd64 libcom-err2 amd64 1.46.5-1ubuntu1 [10.0 kB] Get:88 http://ftpmaster.internal/ubuntu jammy/main amd64 libk5crypto3 amd64 1.19.2-0ubuntu1 [86.3 kB] Get:89 http://ftpmaster.internal/ubuntu jammy/main amd64 libkrb5support0 amd64 1.19.2-0ubuntu1 [32.4 kB] Get:90 http://ftpmaster.internal/ubuntu jammy/main amd64 libkrb5-3 amd64 1.19.2-0ubuntu1 [356 kB] Get:91 http://ftpmaster.internal/ubuntu jammy/main amd64 libgssapi-krb5-2 amd64 1.19.2-0ubuntu1 [144 kB] Get:92 http://ftpmaster.internal/ubuntu jammy/main amd64 libpam-runtime all 1.4.0-10ubuntu2 [40.2 kB] Get:93 http://ftpmaster.internal/ubuntu jammy/main amd64 libsmartcols1 amd64 2.37.2-4ubuntu1 [50.9 kB] Get:94 http://ftpmaster.internal/ubuntu jammy/main amd64 libtsan0 amd64 11.2.0-13ubuntu1 [2260 kB] Get:95 http://ftpmaster.internal/ubuntu jammy/main amd64 libasan6 amd64 11.2.0-13ubuntu1 [2281 kB] Get:96 http://ftpmaster.internal/ubuntu jammy/main amd64 g++-11 amd64 11.2.0-13ubuntu1 [11.4 MB] Get:97 http://ftpmaster.internal/ubuntu jammy/main amd64 gcc-11 amd64 11.2.0-13ubuntu1 [20.1 MB] Get:98 http://ftpmaster.internal/ubuntu jammy/main amd64 libstdc++-11-dev amd64 11.2.0-13ubuntu1 [2103 kB] Get:99 http://ftpmaster.internal/ubuntu jammy/main amd64 libgcc-11-dev amd64 11.2.0-13ubuntu1 [2527 kB] Get:100 http://ftpmaster.internal/ubuntu jammy/main amd64 libisl23 amd64 0.24-2 [728 kB] Get:101 http://ftpmaster.internal/ubuntu jammy/main amd64 libmpc3 amd64 1.2.1-1 [46.9 kB] Get:102 http://ftpmaster.internal/ubuntu jammy/main amd64 libctf0 amd64 2.37-10ubuntu1 [103 kB] Get:103 http://ftpmaster.internal/ubuntu jammy/main amd64 libctf-nobfd0 amd64 2.37-10ubuntu1 [106 kB] Get:104 http://ftpmaster.internal/ubuntu jammy/main amd64 binutils-x86-64-linux-gnu amd64 2.37-10ubuntu1 [2314 kB] Get:105 http://ftpmaster.internal/ubuntu jammy/main amd64 libbinutils amd64 2.37-10ubuntu1 [653 kB] Get:106 http://ftpmaster.internal/ubuntu jammy/main amd64 binutils amd64 2.37-10ubuntu1 [3192 B] Get:107 http://ftpmaster.internal/ubuntu jammy/main amd64 binutils-common amd64 2.37-10ubuntu1 [213 kB] Get:108 http://ftpmaster.internal/ubuntu jammy/main amd64 cpp-11 amd64 11.2.0-13ubuntu1 [9960 kB] Get:109 http://ftpmaster.internal/ubuntu jammy/main amd64 gcc-11-base amd64 11.2.0-13ubuntu1 [21.1 kB] Get:110 http://ftpmaster.internal/ubuntu jammy/main amd64 libss2 amd64 1.46.5-1ubuntu1 [12.3 kB] Get:111 http://ftpmaster.internal/ubuntu jammy/main amd64 sensible-utils all 0.0.17 [20.1 kB] Get:112 http://ftpmaster.internal/ubuntu jammy/main amd64 usrmerge all 25ubuntu2 [54.7 kB] Get:113 http://ftpmaster.internal/ubuntu jammy/main amd64 openssl amd64 3.0.0-1ubuntu1 [1180 kB] Get:114 http://ftpmaster.internal/ubuntu jammy/main amd64 ca-certificates all 20211016 [148 kB] Get:115 http://ftpmaster.internal/ubuntu jammy/main amd64 libgdbm6 amd64 1.22-1 [35.2 kB] Get:116 http://ftpmaster.internal/ubuntu jammy/main amd64 make amd64 4.3-4ubuntu2 [179 kB] Get:117 http://ftpmaster.internal/ubuntu jammy/main amd64 lto-disabled-list all 18 [12.2 kB] Get:118 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-psutil amd64 5.8.0-2 [157 kB] Get:119 http://ftpmaster.internal/ubuntu jammy/main amd64 gpg amd64 2.2.27-3ubuntu1 [517 kB] Get:120 http://ftpmaster.internal/ubuntu jammy/main amd64 gpgconf amd64 2.2.27-3ubuntu1 [94.4 kB] Get:121 http://ftpmaster.internal/ubuntu jammy/main amd64 gpg-agent amd64 2.2.27-3ubuntu1 [209 kB] Get:122 http://ftpmaster.internal/ubuntu jammy/main amd64 libgdbm-compat4 amd64 1.22-1 [6450 B] Get:123 http://ftpmaster.internal/ubuntu jammy/main amd64 lockfile-progs amd64 0.1.19 [10.0 kB] Get:124 http://ftpmaster.internal/ubuntu jammy/main amd64 pkgbinarymangler all 149 [32.4 kB] debconf: delaying package configuration, since apt-utils is not installed Fetched 88.9 MB in 1s (106 MB/s) (Reading database ... 13258 files and directories currently installed.) Preparing to unpack .../debconf_1.5.79_all.deb ... Unpacking debconf (1.5.79) over (1.5.77) ... Setting up debconf (1.5.79) ... (Reading database ... 13257 files and directories currently installed.) Preparing to unpack .../libpam0g_1.4.0-10ubuntu2_amd64.deb ... Unpacking libpam0g:amd64 (1.4.0-10ubuntu2) over (1.3.1-5ubuntu11) ... Setting up libpam0g:amd64 (1.4.0-10ubuntu2) ... Checking for services that may need to be restarted...Checking init scripts... Nothing to restart. (Reading database ... 13257 files and directories currently installed.) Preparing to unpack .../libcrypt-dev_1%3a4.4.27-1_amd64.deb ... Unpacking libcrypt-dev:amd64 (1:4.4.27-1) over (1:4.4.18-4ubuntu2) ... Preparing to unpack .../libcrypt1_1%3a4.4.27-1_amd64.deb ... Unpacking libcrypt1:amd64 (1:4.4.27-1) over (1:4.4.18-4ubuntu2) ... Setting up libcrypt1:amd64 (1:4.4.27-1) ... (Reading database ... 13257 files and directories currently installed.) Preparing to unpack .../base-files_12ubuntu2_amd64.deb ... Unpacking base-files (12ubuntu2) over (12ubuntu1) ... Setting up base-files (12ubuntu2) ... (Reading database ... 13257 files and directories currently installed.) Preparing to unpack .../debianutils_5.5-1ubuntu1_amd64.deb ... Unpacking debianutils (5.5-1ubuntu1) over (4.11.2build1) ... Setting up debianutils (5.5-1ubuntu1) ... update-alternatives: using /usr/bin/which.debianutils to provide /usr/bin/which (which) in auto mode (Reading database ... 13261 files and directories currently installed.) Preparing to unpack .../bash_5.1-6ubuntu1_amd64.deb ... Unpacking bash (5.1-6ubuntu1) over (5.1-3ubuntu2) ... Setting up bash (5.1-6ubuntu1) ... update-alternatives: using /usr/share/man/man7/bash-builtins.7.gz to provide /usr/share/man/man7/builtins.7.gz (builtins.7.gz) in auto mode (Reading database ... 13261 files and directories currently installed.) Preparing to unpack .../bsdutils_1%3a2.37.2-4ubuntu1_amd64.deb ... Unpacking bsdutils (1:2.37.2-4ubuntu1) over (1:2.36.1-8ubuntu1) ... Setting up bsdutils (1:2.37.2-4ubuntu1) ... (Reading database ... 13261 files and directories currently installed.) Preparing to unpack .../libgpg-error0_1.43-1_amd64.deb ... Unpacking libgpg-error0:amd64 (1.43-1) over (1.38-2build2) ... Setting up libgpg-error0:amd64 (1.43-1) ... (Reading database ... 13261 files and directories currently installed.) Preparing to unpack .../libgcrypt20_1.9.4-3ubuntu2_amd64.deb ... Unpacking libgcrypt20:amd64 (1.9.4-3ubuntu2) over (1.8.7-5ubuntu2) ... Setting up libgcrypt20:amd64 (1.9.4-3ubuntu2) ... (Reading database ... 13261 files and directories currently installed.) Preparing to unpack .../bzip2_1.0.8-5_amd64.deb ... Unpacking bzip2 (1.0.8-5) over (1.0.8-4ubuntu4) ... Preparing to unpack .../libbz2-1.0_1.0.8-5_amd64.deb ... Unpacking libbz2-1.0:amd64 (1.0.8-5) over (1.0.8-4ubuntu4) ... Setting up libbz2-1.0:amd64 (1.0.8-5) ... Selecting previously unselected package gcc-12-base:amd64. (Reading database ... 13261 files and directories currently installed.) Preparing to unpack .../gcc-12-base_12-20220106-1ubuntu1_amd64.deb ... Unpacking gcc-12-base:amd64 (12-20220106-1ubuntu1) ... Setting up gcc-12-base:amd64 (12-20220106-1ubuntu1) ... (Reading database ... 13266 files and directories currently installed.) Preparing to unpack .../libgcc-s1_12-20220106-1ubuntu1_amd64.deb ... Unpacking libgcc-s1:amd64 (12-20220106-1ubuntu1) over (11.2.0-7ubuntu2) ... Setting up libgcc-s1:amd64 (12-20220106-1ubuntu1) ... (Reading database ... 13266 files and directories currently installed.) Preparing to unpack .../libstdc++6_12-20220106-1ubuntu1_amd64.deb ... Unpacking libstdc++6:amd64 (12-20220106-1ubuntu1) over (11.2.0-7ubuntu2) ... Setting up libstdc++6:amd64 (12-20220106-1ubuntu1) ... Selecting previously unselected package libssl3:amd64. (Reading database ... 13266 files and directories currently installed.) Preparing to unpack .../libssl3_3.0.0-1ubuntu1_amd64.deb ... Unpacking libssl3:amd64 (3.0.0-1ubuntu1) ... Setting up libssl3:amd64 (3.0.0-1ubuntu1) ... (Reading database ... 13277 files and directories currently installed.) Preparing to unpack .../libblkid1_2.37.2-4ubuntu1_amd64.deb ... Unpacking libblkid1:amd64 (2.37.2-4ubuntu1) over (2.36.1-8ubuntu1) ... Setting up libblkid1:amd64 (2.37.2-4ubuntu1) ... (Reading database ... 13277 files and directories currently installed.) Preparing to unpack .../libuuid1_2.37.2-4ubuntu1_amd64.deb ... Unpacking libuuid1:amd64 (2.37.2-4ubuntu1) over (2.36.1-8ubuntu1) ... Setting up libuuid1:amd64 (2.37.2-4ubuntu1) ... (Reading database ... 13277 files and directories currently installed.) Preparing to unpack .../libcryptsetup12_2%3a2.4.2-1ubuntu4_amd64.deb ... Unpacking libcryptsetup12:amd64 (2:2.4.2-1ubuntu4) over (2:2.3.6-0ubuntu1) ... Preparing to unpack .../libidn2-0_2.3.2-2_amd64.deb ... Unpacking libidn2-0:amd64 (2.3.2-2) over (2.3.1-1build1) ... Setting up libidn2-0:amd64 (2.3.2-2) ... (Reading database ... 13279 files and directories currently installed.) Preparing to unpack .../libp11-kit0_0.24.0-6_amd64.deb ... Unpacking libp11-kit0:amd64 (0.24.0-6) over (0.23.22-1build1) ... Setting up libp11-kit0:amd64 (0.24.0-6) ... (Reading database ... 13279 files and directories currently installed.) Preparing to unpack .../libtasn1-6_4.18.0-4_amd64.deb ... Unpacking libtasn1-6:amd64 (4.18.0-4) over (4.16.0-2build1) ... Setting up libtasn1-6:amd64 (4.18.0-4) ... (Reading database ... 13279 files and directories currently installed.) Preparing to unpack .../libgnutls30_3.7.2-4ubuntu1_amd64.deb ... Unpacking libgnutls30:amd64 (3.7.2-4ubuntu1) over (3.7.1-5ubuntu1) ... Setting up libgnutls30:amd64 (3.7.2-4ubuntu1) ... (Reading database ... 13279 files and directories currently installed.) Preparing to unpack .../systemd-sysv_249.5-2ubuntu3_amd64.deb ... Unpacking systemd-sysv (249.5-2ubuntu3) over (248.3-1ubuntu8) ... Preparing to unpack .../systemd-timesyncd_249.5-2ubuntu3_amd64.deb ... Unpacking systemd-timesyncd (249.5-2ubuntu3) over (248.3-1ubuntu8) ... Preparing to unpack .../libapparmor1_3.0.3-0ubuntu5_amd64.deb ... Unpacking libapparmor1:amd64 (3.0.3-0ubuntu5) over (3.0.3-0ubuntu1) ... Preparing to unpack .../libip4tc2_1.8.7-1ubuntu4_amd64.deb ... Unpacking libip4tc2:amd64 (1.8.7-1ubuntu4) over (1.8.7-1ubuntu3) ... Preparing to unpack .../libzstd1_1.4.8+dfsg-3_amd64.deb ... Unpacking libzstd1:amd64 (1.4.8+dfsg-3) over (1.4.8+dfsg-2.1build1) ... Setting up libzstd1:amd64 (1.4.8+dfsg-3) ... (Reading database ... 13279 files and directories currently installed.) Preparing to unpack .../libkmod2_28-1ubuntu5_amd64.deb ... Unpacking libkmod2:amd64 (28-1ubuntu5) over (28-1ubuntu4) ... Preparing to unpack .../libpcre2-8-0_10.39-3_amd64.deb ... Unpacking libpcre2-8-0:amd64 (10.39-3) over (10.37-0ubuntu2) ... Setting up libpcre2-8-0:amd64 (10.39-3) ... (Reading database ... 13279 files and directories currently installed.) Preparing to unpack .../libselinux1_3.3-1_amd64.deb ... Unpacking libselinux1:amd64 (3.3-1) over (3.1-3build2) ... Setting up libselinux1:amd64 (3.3-1) ... (Reading database ... 13279 files and directories currently installed.) Preparing to unpack .../libmount1_2.37.2-4ubuntu1_amd64.deb ... Unpacking libmount1:amd64 (2.37.2-4ubuntu1) over (2.36.1-8ubuntu1) ... Setting up libmount1:amd64 (2.37.2-4ubuntu1) ... (Reading database ... 13279 files and directories currently installed.) Preparing to unpack .../libseccomp2_2.5.2-2ubuntu2_amd64.deb ... Unpacking libseccomp2:amd64 (2.5.2-2ubuntu2) over (2.5.1-1ubuntu1) ... Setting up libseccomp2:amd64 (2.5.2-2ubuntu2) ... (Reading database ... 13279 files and directories currently installed.) Preparing to unpack .../login_1%3a4.8.1-2ubuntu1_amd64.deb ... Unpacking login (1:4.8.1-2ubuntu1) over (1:4.8.1-1ubuntu9) ... Setting up login (1:4.8.1-2ubuntu1) ... (Reading database ... 13279 files and directories currently installed.) Preparing to unpack .../util-linux_2.37.2-4ubuntu1_amd64.deb ... Unpacking util-linux (2.37.2-4ubuntu1) over (2.36.1-8ubuntu1) ... Setting up util-linux (2.37.2-4ubuntu1) ... (Reading database ... 13274 files and directories currently installed.) Preparing to unpack .../mount_2.37.2-4ubuntu1_amd64.deb ... Unpacking mount (2.37.2-4ubuntu1) over (2.36.1-8ubuntu1) ... Preparing to unpack .../systemd_249.5-2ubuntu3_amd64.deb ... Unpacking systemd (249.5-2ubuntu3) over (248.3-1ubuntu8) ... Preparing to unpack .../libsystemd0_249.5-2ubuntu3_amd64.deb ... Unpacking libsystemd0:amd64 (249.5-2ubuntu3) over (248.3-1ubuntu8) ... Setting up libsystemd0:amd64 (249.5-2ubuntu3) ... (Reading database ... 13276 files and directories currently installed.) Preparing to unpack .../libudev1_249.5-2ubuntu3_amd64.deb ... Unpacking libudev1:amd64 (249.5-2ubuntu3) over (248.3-1ubuntu8) ... Setting up libudev1:amd64 (249.5-2ubuntu3) ... (Reading database ... 13276 files and directories currently installed.) Preparing to unpack .../libapt-pkg6.0_2.3.14_amd64.deb ... Unpacking libapt-pkg6.0:amd64 (2.3.14) over (2.3.9) ... Setting up libapt-pkg6.0:amd64 (2.3.14) ... (Reading database ... 13276 files and directories currently installed.) Preparing to unpack .../dpkg_1.21.1ubuntu11_amd64.deb ... Unpacking dpkg (1.21.1ubuntu11) over (1.20.9ubuntu2) ... Setting up dpkg (1.21.1ubuntu11) ... Installing new version of config file /etc/cron.daily/dpkg ... Created symlink /etc/systemd/system/timers.target.wants/dpkg-db-backup.timer -> /lib/systemd/system/dpkg-db-backup.timer. (Reading database ... 13282 files and directories currently installed.) Preparing to unpack .../dash_0.5.11+git20210903+057cd650a4ed-3_amd64.deb ... Unpacking dash (0.5.11+git20210903+057cd650a4ed-3) over (0.5.11+git20210120+802ebd4-1build1) ... Setting up dash (0.5.11+git20210903+057cd650a4ed-3) ... (Reading database ... 13282 files and directories currently installed.) Preparing to unpack .../archives/grep_3.7-1_amd64.deb ... Unpacking grep (3.7-1) over (3.7-0ubuntu1) ... Setting up grep (3.7-1) ... (Reading database ... 13282 files and directories currently installed.) Preparing to unpack .../libncurses6_6.3-1_amd64.deb ... Unpacking libncurses6:amd64 (6.3-1) over (6.2+20201114-2build2) ... Preparing to unpack .../libncursesw6_6.3-1_amd64.deb ... Unpacking libncursesw6:amd64 (6.3-1) over (6.2+20201114-2build2) ... Preparing to unpack .../libtinfo6_6.3-1_amd64.deb ... Unpacking libtinfo6:amd64 (6.3-1) over (6.2+20201114-2build2) ... Setting up libtinfo6:amd64 (6.3-1) ... (Reading database ... 13282 files and directories currently installed.) Preparing to unpack .../ncurses-bin_6.3-1_amd64.deb ... Unpacking ncurses-bin (6.3-1) over (6.2+20201114-2build2) ... Setting up ncurses-bin (6.3-1) ... (Reading database ... 13282 files and directories currently installed.) Preparing to unpack .../sed_4.8-1ubuntu1_amd64.deb ... Unpacking sed (4.8-1ubuntu1) over (4.7-1ubuntu2) ... Setting up sed (4.8-1ubuntu1) ... (Reading database ... 13282 files and directories currently installed.) Preparing to unpack .../init-system-helpers_1.61_all.deb ... Unpacking init-system-helpers (1.61) over (1.60build1) ... Setting up init-system-helpers (1.61) ... (Reading database ... 13282 files and directories currently installed.) Preparing to unpack .../ncurses-base_6.3-1_all.deb ... Unpacking ncurses-base (6.3-1) over (6.2+20201114-2build2) ... Setting up ncurses-base (6.3-1) ... (Reading database ... 13282 files and directories currently installed.) Preparing to unpack .../gpgv_2.2.27-3ubuntu1_amd64.deb ... Unpacking gpgv (2.2.27-3ubuntu1) over (2.2.20-1ubuntu4) ... Setting up gpgv (2.2.27-3ubuntu1) ... (Reading database ... 13282 files and directories currently installed.) Preparing to unpack .../archives/apt_2.3.14_amd64.deb ... Unpacking apt (2.3.14) over (2.3.9) ... Setting up apt (2.3.14) ... Installing new version of config file /etc/cron.daily/apt-compat ... Selecting previously unselected package libsepol2:amd64. (Reading database ... 13281 files and directories currently installed.) Preparing to unpack .../libsepol2_3.3-1_amd64.deb ... Unpacking libsepol2:amd64 (3.3-1) ... Setting up libsepol2:amd64 (3.3-1) ... (Reading database ... 13285 files and directories currently installed.) Preparing to unpack .../libsemanage-common_3.3-1_all.deb ... Unpacking libsemanage-common (3.3-1) over (3.1-1ubuntu3) ... Setting up libsemanage-common (3.3-1) ... Selecting previously unselected package libsemanage2:amd64. (Reading database ... 13285 files and directories currently installed.) Preparing to unpack .../libsemanage2_3.3-1_amd64.deb ... Unpacking libsemanage2:amd64 (3.3-1) ... Setting up libsemanage2:amd64 (3.3-1) ... (Reading database ... 13289 files and directories currently installed.) Preparing to unpack .../passwd_1%3a4.8.1-2ubuntu1_amd64.deb ... Unpacking passwd (1:4.8.1-2ubuntu1) over (1:4.8.1-1ubuntu9) ... Setting up passwd (1:4.8.1-2ubuntu1) ... (Reading database ... 13296 files and directories currently installed.) Removing libsemanage1:amd64 (3.1-1ubuntu3) ... (Reading database ... 13292 files and directories currently installed.) Preparing to unpack .../libpam-modules-bin_1.4.0-10ubuntu2_amd64.deb ... Unpacking libpam-modules-bin (1.4.0-10ubuntu2) over (1.3.1-5ubuntu11) ... Setting up libpam-modules-bin (1.4.0-10ubuntu2) ... (Reading database ... 13290 files and directories currently installed.) Preparing to unpack .../libpam-modules_1.4.0-10ubuntu2_amd64.deb ... Unpacking libpam-modules:amd64 (1.4.0-10ubuntu2) over (1.3.1-5ubuntu11) ... Setting up libpam-modules:amd64 (1.4.0-10ubuntu2) ... Installing new version of config file /etc/security/namespace.conf ... Installing new version of config file /etc/security/pam_env.conf ... (Reading database ... 13291 files and directories currently installed.) Preparing to unpack .../logsave_1.46.5-1ubuntu1_amd64.deb ... Unpacking logsave (1.46.5-1ubuntu1) over (1.46.3-1ubuntu3) ... Preparing to unpack .../libext2fs2_1.46.5-1ubuntu1_amd64.deb ... Unpacking libext2fs2:amd64 (1.46.5-1ubuntu1) over (1.46.3-1ubuntu3) ... Setting up libext2fs2:amd64 (1.46.5-1ubuntu1) ... (Reading database ... 13291 files and directories currently installed.) Preparing to unpack .../e2fsprogs_1.46.5-1ubuntu1_amd64.deb ... Unpacking e2fsprogs (1.46.5-1ubuntu1) over (1.46.3-1ubuntu3) ... Setting up libapparmor1:amd64 (3.0.3-0ubuntu5) ... Setting up libcryptsetup12:amd64 (2:2.4.2-1ubuntu4) ... Setting up libip4tc2:amd64 (1.8.7-1ubuntu4) ... Setting up libkmod2:amd64 (28-1ubuntu5) ... Setting up mount (2.37.2-4ubuntu1) ... Setting up systemd (249.5-2ubuntu3) ... Installing new version of config file /etc/systemd/networkd.conf ... Installing new version of config file /etc/systemd/resolved.conf ... Initializing machine ID from random generator. Setting up systemd-sysv (249.5-2ubuntu3) ... (Reading database ... 13291 files and directories currently installed.) Preparing to unpack .../archives/init_1.61_amd64.deb ... Unpacking init (1.61) over (1.60build1) ... Selecting previously unselected package libpython3.9-minimal:amd64. Preparing to unpack .../libpython3.9-minimal_3.9.9-2_amd64.deb ... Unpacking libpython3.9-minimal:amd64 (3.9.9-2) ... Selecting previously unselected package libexpat1:amd64. Preparing to unpack .../libexpat1_2.4.2-1_amd64.deb ... Unpacking libexpat1:amd64 (2.4.2-1) ... Selecting previously unselected package python3.9-minimal. Preparing to unpack .../python3.9-minimal_3.9.9-2_amd64.deb ... Unpacking python3.9-minimal (3.9.9-2) ... Setting up libpython3.9-minimal:amd64 (3.9.9-2) ... Setting up libexpat1:amd64 (2.4.2-1) ... Setting up python3.9-minimal (3.9.9-2) ... Selecting previously unselected package python3-minimal. (Reading database ... 13584 files and directories currently installed.) Preparing to unpack .../0-python3-minimal_3.9.7-4_amd64.deb ... Unpacking python3-minimal (3.9.7-4) ... Selecting previously unselected package media-types. Preparing to unpack .../1-media-types_4.0.0_all.deb ... Unpacking media-types (4.0.0) ... Preparing to unpack .../2-tzdata_2021e-1ubuntu1_all.deb ... Unpacking tzdata (2021e-1ubuntu1) over (2021a-2ubuntu1) ... Selecting previously unselected package libmpdec3:amd64. Preparing to unpack .../3-libmpdec3_2.5.1-2build1_amd64.deb ... Unpacking libmpdec3:amd64 (2.5.1-2build1) ... Preparing to unpack .../4-readline-common_8.1.2-1_all.deb ... Unpacking readline-common (8.1.2-1) over (8.1-2build1) ... Preparing to unpack .../5-libreadline8_8.1.2-1_amd64.deb ... Unpacking libreadline8:amd64 (8.1.2-1) over (8.1-2build1) ... Preparing to unpack .../6-libsqlite3-0_3.36.0-2_amd64.deb ... Unpacking libsqlite3-0:amd64 (3.36.0-2) over (3.35.5-1) ... Selecting previously unselected package libpython3.9-stdlib:amd64. Preparing to unpack .../7-libpython3.9-stdlib_3.9.9-2_amd64.deb ... Unpacking libpython3.9-stdlib:amd64 (3.9.9-2) ... Selecting previously unselected package python3.9. Preparing to unpack .../8-python3.9_3.9.9-2_amd64.deb ... Unpacking python3.9 (3.9.9-2) ... Selecting previously unselected package libpython3-stdlib:amd64. Preparing to unpack .../9-libpython3-stdlib_3.9.7-4_amd64.deb ... Unpacking libpython3-stdlib:amd64 (3.9.7-4) ... Setting up python3-minimal (3.9.7-4) ... Selecting previously unselected package python3. (Reading database ... 13984 files and directories currently installed.) Preparing to unpack .../python3_3.9.7-4_amd64.deb ... Unpacking python3 (3.9.7-4) ... Preparing to unpack .../libattr1_1%3a2.5.1-1_amd64.deb ... Unpacking libattr1:amd64 (1:2.5.1-1) over (1:2.4.48-6build2) ... Setting up libattr1:amd64 (1:2.5.1-1) ... Installing new version of config file /etc/xattr.conf ... (Reading database ... 14004 files and directories currently installed.) Preparing to unpack .../libcom-err2_1.46.5-1ubuntu1_amd64.deb ... Unpacking libcom-err2:amd64 (1.46.5-1ubuntu1) over (1.46.3-1ubuntu3) ... Setting up libcom-err2:amd64 (1.46.5-1ubuntu1) ... (Reading database ... 14004 files and directories currently installed.) Preparing to unpack .../libk5crypto3_1.19.2-0ubuntu1_amd64.deb ... Unpacking libk5crypto3:amd64 (1.19.2-0ubuntu1) over (1.18.3-6) ... Setting up libk5crypto3:amd64 (1.19.2-0ubuntu1) ... (Reading database ... 14004 files and directories currently installed.) Preparing to unpack .../libkrb5support0_1.19.2-0ubuntu1_amd64.deb ... Unpacking libkrb5support0:amd64 (1.19.2-0ubuntu1) over (1.18.3-6) ... Setting up libkrb5support0:amd64 (1.19.2-0ubuntu1) ... (Reading database ... 14004 files and directories currently installed.) Preparing to unpack .../libkrb5-3_1.19.2-0ubuntu1_amd64.deb ... Unpacking libkrb5-3:amd64 (1.19.2-0ubuntu1) over (1.18.3-6) ... Setting up libkrb5-3:amd64 (1.19.2-0ubuntu1) ... (Reading database ... 14004 files and directories currently installed.) Preparing to unpack .../libgssapi-krb5-2_1.19.2-0ubuntu1_amd64.deb ... Unpacking libgssapi-krb5-2:amd64 (1.19.2-0ubuntu1) over (1.18.3-6) ... Setting up libgssapi-krb5-2:amd64 (1.19.2-0ubuntu1) ... (Reading database ... 14004 files and directories currently installed.) Preparing to unpack .../libpam-runtime_1.4.0-10ubuntu2_all.deb ... Unpacking libpam-runtime (1.4.0-10ubuntu2) over (1.3.1-5ubuntu11) ... Setting up libpam-runtime (1.4.0-10ubuntu2) ... (Reading database ... 14004 files and directories currently installed.) Preparing to unpack .../libsmartcols1_2.37.2-4ubuntu1_amd64.deb ... Unpacking libsmartcols1:amd64 (2.37.2-4ubuntu1) over (2.36.1-8ubuntu1) ... Setting up libsmartcols1:amd64 (2.37.2-4ubuntu1) ... (Reading database ... 14004 files and directories currently installed.) Preparing to unpack .../00-libtsan0_11.2.0-13ubuntu1_amd64.deb ... Unpacking libtsan0:amd64 (11.2.0-13ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../01-libgomp1_12-20220106-1ubuntu1_amd64.deb ... Unpacking libgomp1:amd64 (12-20220106-1ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../02-libitm1_12-20220106-1ubuntu1_amd64.deb ... Unpacking libitm1:amd64 (12-20220106-1ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../03-libatomic1_12-20220106-1ubuntu1_amd64.deb ... Unpacking libatomic1:amd64 (12-20220106-1ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../04-libasan6_11.2.0-13ubuntu1_amd64.deb ... Unpacking libasan6:amd64 (11.2.0-13ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../05-liblsan0_12-20220106-1ubuntu1_amd64.deb ... Unpacking liblsan0:amd64 (12-20220106-1ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../06-libubsan1_12-20220106-1ubuntu1_amd64.deb ... Unpacking libubsan1:amd64 (12-20220106-1ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../07-libquadmath0_12-20220106-1ubuntu1_amd64.deb ... Unpacking libquadmath0:amd64 (12-20220106-1ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../08-g++-11_11.2.0-13ubuntu1_amd64.deb ... Unpacking g++-11 (11.2.0-13ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../09-gcc-11_11.2.0-13ubuntu1_amd64.deb ... Unpacking gcc-11 (11.2.0-13ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../10-libstdc++-11-dev_11.2.0-13ubuntu1_amd64.deb ... Unpacking libstdc++-11-dev:amd64 (11.2.0-13ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../11-libgcc-11-dev_11.2.0-13ubuntu1_amd64.deb ... Unpacking libgcc-11-dev:amd64 (11.2.0-13ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../12-libisl23_0.24-2_amd64.deb ... Unpacking libisl23:amd64 (0.24-2) over (0.24-1build1) ... Preparing to unpack .../13-libmpc3_1.2.1-1_amd64.deb ... Unpacking libmpc3:amd64 (1.2.1-1) over (1.2.0-1build2) ... Preparing to unpack .../14-libcc1-0_12-20220106-1ubuntu1_amd64.deb ... Unpacking libcc1-0:amd64 (12-20220106-1ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../15-libctf0_2.37-10ubuntu1_amd64.deb ... Unpacking libctf0:amd64 (2.37-10ubuntu1) over (2.37-7ubuntu1) ... Preparing to unpack .../16-libctf-nobfd0_2.37-10ubuntu1_amd64.deb ... Unpacking libctf-nobfd0:amd64 (2.37-10ubuntu1) over (2.37-7ubuntu1) ... Preparing to unpack .../17-binutils-x86-64-linux-gnu_2.37-10ubuntu1_amd64.deb ... Unpacking binutils-x86-64-linux-gnu (2.37-10ubuntu1) over (2.37-7ubuntu1) ... Preparing to unpack .../18-libbinutils_2.37-10ubuntu1_amd64.deb ... Unpacking libbinutils:amd64 (2.37-10ubuntu1) over (2.37-7ubuntu1) ... Preparing to unpack .../19-binutils_2.37-10ubuntu1_amd64.deb ... Unpacking binutils (2.37-10ubuntu1) over (2.37-7ubuntu1) ... Preparing to unpack .../20-binutils-common_2.37-10ubuntu1_amd64.deb ... Unpacking binutils-common:amd64 (2.37-10ubuntu1) over (2.37-7ubuntu1) ... Preparing to unpack .../21-cpp-11_11.2.0-13ubuntu1_amd64.deb ... Unpacking cpp-11 (11.2.0-13ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../22-gcc-11-base_11.2.0-13ubuntu1_amd64.deb ... Unpacking gcc-11-base:amd64 (11.2.0-13ubuntu1) over (11.2.0-7ubuntu2) ... Preparing to unpack .../23-libss2_1.46.5-1ubuntu1_amd64.deb ... Unpacking libss2:amd64 (1.46.5-1ubuntu1) over (1.46.3-1ubuntu3) ... Preparing to unpack .../24-sensible-utils_0.0.17_all.deb ... Unpacking sensible-utils (0.0.17) over (0.0.14) ... Preparing to unpack .../25-usrmerge_25ubuntu2_all.deb ... Unpacking usrmerge (25ubuntu2) over (25ubuntu1) ... Preparing to unpack .../26-openssl_3.0.0-1ubuntu1_amd64.deb ... Unpacking openssl (3.0.0-1ubuntu1) over (1.1.1l-1ubuntu1) ... Preparing to unpack .../27-ca-certificates_20211016_all.deb ... Unpacking ca-certificates (20211016) over (20210119ubuntu1) ... Preparing to unpack .../28-libgdbm6_1.22-1_amd64.deb ... Unpacking libgdbm6:amd64 (1.22-1) over (1.19-2build1) ... Preparing to unpack .../29-dpkg-dev_1.21.1ubuntu11_all.deb ... Unpacking dpkg-dev (1.21.1ubuntu11) over (1.20.9ubuntu2) ... Preparing to unpack .../30-libdpkg-perl_1.21.1ubuntu11_all.deb ... Unpacking libdpkg-perl (1.21.1ubuntu11) over (1.20.9ubuntu2) ... Preparing to unpack .../31-make_4.3-4ubuntu2_amd64.deb ... Unpacking make (4.3-4ubuntu2) over (4.3-4ubuntu1) ... Preparing to unpack .../32-lto-disabled-list_18_all.deb ... Unpacking lto-disabled-list (18) over (16) ... Selecting previously unselected package python3-psutil. Preparing to unpack .../33-python3-psutil_5.8.0-2_amd64.deb ... Unpacking python3-psutil (5.8.0-2) ... Preparing to unpack .../34-gpg_2.2.27-3ubuntu1_amd64.deb ... Unpacking gpg (2.2.27-3ubuntu1) over (2.2.20-1ubuntu4) ... Preparing to unpack .../35-gpgconf_2.2.27-3ubuntu1_amd64.deb ... Unpacking gpgconf (2.2.27-3ubuntu1) over (2.2.20-1ubuntu4) ... Preparing to unpack .../36-gpg-agent_2.2.27-3ubuntu1_amd64.deb ... Unpacking gpg-agent (2.2.27-3ubuntu1) over (2.2.20-1ubuntu4) ... Preparing to unpack .../37-libgdbm-compat4_1.22-1_amd64.deb ... Unpacking libgdbm-compat4:amd64 (1.22-1) over (1.19-2build1) ... Preparing to unpack .../38-lockfile-progs_0.1.19_amd64.deb ... Unpacking lockfile-progs (0.1.19) over (0.1.18build1) ... Preparing to unpack .../39-pkgbinarymangler_149_all.deb ... Unpacking pkgbinarymangler (149) over (148) ... Setting up media-types (4.0.0) ... Setting up gcc-11-base:amd64 (11.2.0-13ubuntu1) ... Setting up lto-disabled-list (18) ... Setting up init (1.61) ... Setting up libsqlite3-0:amd64 (3.36.0-2) ... Setting up binutils-common:amd64 (2.37-10ubuntu1) ... Setting up libctf-nobfd0:amd64 (2.37-10ubuntu1) ... Setting up libgomp1:amd64 (12-20220106-1ubuntu1) ... Setting up bzip2 (1.0.8-5) ... Setting up libasan6:amd64 (11.2.0-13ubuntu1) ... Setting up tzdata (2021e-1ubuntu1) ... Current default time zone: 'Etc/UTC' Local time is now: Tue Jan 11 01:18:49 UTC 2022. Universal Time is now: Tue Jan 11 01:18:49 UTC 2022. Run 'dpkg-reconfigure tzdata' if you wish to change it. Setting up make (4.3-4ubuntu2) ... Setting up libncurses6:amd64 (6.3-1) ... Setting up libquadmath0:amd64 (12-20220106-1ubuntu1) ... Setting up libmpc3:amd64 (1.2.1-1) ... Setting up systemd-timesyncd (249.5-2ubuntu3) ... Setting up lockfile-progs (0.1.19) ... Setting up libatomic1:amd64 (12-20220106-1ubuntu1) ... Setting up usrmerge (25ubuntu2) ... Setting up libss2:amd64 (1.46.5-1ubuntu1) ... Setting up libncursesw6:amd64 (6.3-1) ... Setting up libdpkg-perl (1.21.1ubuntu11) ... Setting up logsave (1.46.5-1ubuntu1) ... Setting up libubsan1:amd64 (12-20220106-1ubuntu1) ... Setting up sensible-utils (0.0.17) ... Setting up libcrypt-dev:amd64 (1:4.4.27-1) ... Setting up libmpdec3:amd64 (2.5.1-2build1) ... Setting up libbinutils:amd64 (2.37-10ubuntu1) ... Setting up libisl23:amd64 (0.24-2) ... Setting up openssl (3.0.0-1ubuntu1) ... Installing new version of config file /etc/ssl/openssl.cnf ... Setting up readline-common (8.1.2-1) ... Setting up libcc1-0:amd64 (12-20220106-1ubuntu1) ... Setting up liblsan0:amd64 (12-20220106-1ubuntu1) ... Setting up libitm1:amd64 (12-20220106-1ubuntu1) ... Setting up libgdbm6:amd64 (1.22-1) ... Setting up libtsan0:amd64 (11.2.0-13ubuntu1) ... Setting up libctf0:amd64 (2.37-10ubuntu1) ... Setting up cpp-11 (11.2.0-13ubuntu1) ... Setting up pkgbinarymangler (149) ... Setting up libreadline8:amd64 (8.1.2-1) ... Setting up e2fsprogs (1.46.5-1ubuntu1) ... Installing new version of config file /etc/mke2fs.conf ... Setting up ca-certificates (20211016) ... Updating certificates in /etc/ssl/certs... rehash: warning: skipping ca-certificates.crt,it does not contain exactly one certificate or CRL 7 added, 8 removed; done. Setting up libgdbm-compat4:amd64 (1.22-1) ... Setting up libgcc-11-dev:amd64 (11.2.0-13ubuntu1) ... Setting up gpgconf (2.2.27-3ubuntu1) ... Setting up gpg (2.2.27-3ubuntu1) ... Setting up libpython3.9-stdlib:amd64 (3.9.9-2) ... Setting up libpython3-stdlib:amd64 (3.9.7-4) ... Setting up binutils-x86-64-linux-gnu (2.37-10ubuntu1) ... Setting up gpg-agent (2.2.27-3ubuntu1) ... Setting up binutils (2.37-10ubuntu1) ... Setting up libstdc++-11-dev:amd64 (11.2.0-13ubuntu1) ... Setting up gcc-11 (11.2.0-13ubuntu1) ... Setting up python3.9 (3.9.9-2) ... Setting up g++-11 (11.2.0-13ubuntu1) ... Setting up python3 (3.9.7-4) ... Setting up python3-psutil (5.8.0-2) ... Setting up dpkg-dev (1.21.1ubuntu11) ... Processing triggers for libc-bin (2.34-0ubuntu3) ... Processing triggers for ca-certificates (20211016) ... Updating certificates in /etc/ssl/certs... 0 added, 0 removed; done. Running hooks in /etc/ca-certificates/update.d... done. RUN: /usr/share/launchpad-buildd/bin/sbuild-package PACKAGEBUILD-22760933 amd64 jammy -c chroot:build-PACKAGEBUILD-22760933 --arch=amd64 --dist=jammy --nolog -A fastapi_0.63.0-2.dsc Initiating build PACKAGEBUILD-22760933 with 4 jobs across 4 processor cores. Kernel reported to sbuild: 4.15.0-166-generic #174-Ubuntu SMP Wed Dec 8 19:07:44 UTC 2021 x86_64 sbuild (Debian sbuild) 0.75.0 (21 Mar 2018) on lcy02-amd64-032.buildd +==============================================================================+ | fastapi 0.63.0-2 (amd64) Tue, 11 Jan 2022 01:18:52 +0000 | +==============================================================================+ Package: fastapi Version: 0.63.0-2 Source Version: 0.63.0-2 Distribution: jammy Machine Architecture: amd64 Host Architecture: amd64 Build Architecture: amd64 Build Type: binary I: NOTICE: Log filtering will replace 'home/buildd/build-PACKAGEBUILD-22760933/chroot-autobuild' with '<>' +------------------------------------------------------------------------------+ | Fetch source files | +------------------------------------------------------------------------------+ Local sources ------------- fastapi_0.63.0-2.dsc exists in .; copying to chroot I: NOTICE: Log filtering will replace 'build/fastapi-8BWOVI/fastapi-0.63.0' with '<>' I: NOTICE: Log filtering will replace 'build/fastapi-8BWOVI' with '<>' +------------------------------------------------------------------------------+ | Install build-essential | +------------------------------------------------------------------------------+ Setup apt archive ----------------- Merged Build-Depends: build-essential, fakeroot Filtered Build-Depends: build-essential, fakeroot dpkg-deb: building package 'sbuild-build-depends-core-dummy' in '/<>/resolver-LHg2Wo/apt_archive/sbuild-build-depends-core-dummy.deb'. dpkg-scanpackages: warning: Packages in archive but missing from override file: dpkg-scanpackages: warning: sbuild-build-depends-core-dummy dpkg-scanpackages: info: Wrote 1 entries to output Packages file. Ign:1 copy:/<>/resolver-LHg2Wo/apt_archive ./ InRelease Get:2 copy:/<>/resolver-LHg2Wo/apt_archive ./ Release [957 B] Ign:3 copy:/<>/resolver-LHg2Wo/apt_archive ./ Release.gpg Get:4 copy:/<>/resolver-LHg2Wo/apt_archive ./ Sources [349 B] Get:5 copy:/<>/resolver-LHg2Wo/apt_archive ./ Packages [432 B] Fetched 1738 B in 0s (170 kB/s) Reading package lists... Reading package lists... Install core build dependencies (apt-based resolver) ---------------------------------------------------- Installing build dependencies Reading package lists... Building dependency tree... Reading state information... The following packages were automatically installed and are no longer required: libssl1.1 systemd-timesyncd Use 'apt autoremove' to remove them. The following NEW packages will be installed: sbuild-build-depends-core-dummy 0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded. Need to get 650 B of archives. After this operation, 0 B of additional disk space will be used. Get:1 copy:/<>/resolver-LHg2Wo/apt_archive ./ sbuild-build-depends-core-dummy 0.invalid.0 [650 B] debconf: delaying package configuration, since apt-utils is not installed Fetched 650 B in 0s (0 B/s) Selecting previously unselected package sbuild-build-depends-core-dummy. (Reading database ... 14211 files and directories currently installed.) Preparing to unpack .../sbuild-build-depends-core-dummy_0.invalid.0_amd64.deb ... Unpacking sbuild-build-depends-core-dummy (0.invalid.0) ... Setting up sbuild-build-depends-core-dummy (0.invalid.0) ... +------------------------------------------------------------------------------+ | Check architectures | +------------------------------------------------------------------------------+ Arch check ok (amd64 included in all) +------------------------------------------------------------------------------+ | Install package build dependencies | +------------------------------------------------------------------------------+ Setup apt archive ----------------- Merged Build-Depends: debhelper-compat (= 13), dh-python, python3-aiofiles, python3-aiosqlite, python3-all, python3-databases, python3-email-validator, python3-flask, python3-httpx, python3-multipart, python3-peewee, python3-pydantic, python3-pytest, python3-pytest-asyncio, python3-requests, python3-starlette, python3-ujson Filtered Build-Depends: debhelper-compat (= 13), dh-python, python3-aiofiles, python3-aiosqlite, python3-all, python3-databases, python3-email-validator, python3-flask, python3-httpx, python3-multipart, python3-peewee, python3-pydantic, python3-pytest, python3-pytest-asyncio, python3-requests, python3-starlette, python3-ujson dpkg-deb: building package 'sbuild-build-depends-fastapi-dummy' in '/<>/resolver-LHg2Wo/apt_archive/sbuild-build-depends-fastapi-dummy.deb'. dpkg-scanpackages: warning: Packages in archive but missing from override file: dpkg-scanpackages: warning: sbuild-build-depends-core-dummy sbuild-build-depends-fastapi-dummy dpkg-scanpackages: info: Wrote 2 entries to output Packages file. Ign:1 copy:/<>/resolver-LHg2Wo/apt_archive ./ InRelease Get:2 copy:/<>/resolver-LHg2Wo/apt_archive ./ Release [963 B] Ign:3 copy:/<>/resolver-LHg2Wo/apt_archive ./ Release.gpg Get:4 copy:/<>/resolver-LHg2Wo/apt_archive ./ Sources [617 B] Get:5 copy:/<>/resolver-LHg2Wo/apt_archive ./ Packages [686 B] Fetched 2266 B in 0s (0 B/s) Reading package lists... Reading package lists... Install fastapi build dependencies (apt-based resolver) ------------------------------------------------------- Installing build dependencies Reading package lists... Building dependency tree... Reading state information... The following packages were automatically installed and are no longer required: libssl1.1 systemd-timesyncd Use 'apt autoremove' to remove them. The following additional packages will be installed: autoconf automake autopoint autotools-dev bsdextrautils debhelper debugedit dh-autoreconf dh-python dh-strip-nondeterminism dwz file gettext gettext-base groff-base intltool-debian libarchive-zip-perl libbsd0 libdebhelper-perl libdouble-conversion3 libdw1 libedit2 libelf1 libfile-stripnondeterminism-perl libicu67 libjs-jquery libmagic-mgc libmagic1 libmd0 libpipeline1 libpython3.10-minimal libpython3.10-stdlib libsigsegv2 libsub-override-perl libtool libuchardet0 libxml2 m4 man-db netbase po-debconf python-babel-localedata python3-aiofiles python3-aiosqlite python3-all python3-anyio python3-async-generator python3-attr python3-babel python3-certifi python3-chardet python3-click python3-colorama python3-databases python3-distutils python3-dnspython python3-email-validator python3-flask python3-h11 python3-httpcore python3-httpx python3-idna python3-importlib-metadata python3-iniconfig python3-itsdangerous python3-jinja2 python3-lib2to3 python3-markupsafe python3-more-itertools python3-multipart python3-packaging python3-peewee python3-pkg-resources python3-pluggy python3-py python3-pydantic python3-pyparsing python3-pytest python3-pytest-asyncio python3-requests python3-rfc3986 python3-six python3-sniffio python3-sqlalchemy python3-starlette python3-toml python3-typing-extensions python3-tz python3-ujson python3-urllib3 python3-werkzeug python3-zipp python3.10 python3.10-minimal Suggested packages: autoconf-archive gnu-standards autoconf-doc dh-make flit python3-build python3-tomli python3-installer gettext-doc libasprintf-dev libgettextpo-dev groff libtool-doc gfortran | fortran95-compiler gcj-jdk m4-doc apparmor less www-browser libmail-box-perl python-aiosqlite-doc python-attr-doc python3-asyncpg | python3-aiopg python3-aiomysql python3-psycopg2 python3-pymysql python3-trio python3-asgiref python3-dotenv python-flask-doc python-jinja2-doc python3-setuptools subversion python-pyparsing-doc python3-cryptography python3-openssl python3-socks python-requests-doc python-sqlalchemy-doc python3-fdb python3-pymssql python3-mysqldb ipython3 python-werkzeug-doc python3-lxml python3-watchdog python3.10-venv python3.10-doc binfmt-support Recommended packages: curl | wget | lynx libarchive-cpio-perl javascript-common libltdl-dev libmail-sendmail-perl python3-cryptography python3-requests-toolbelt python3-blinker python3-simplejson python3-psycopg2 python3-mysqldb | python3-pymysql python-peewee-doc python3-pygments python3-sqlalchemy-ext python3-uvicorn | python3-daphne python3-graphene python3-yaml python3-openssl python3-pyinotify The following NEW packages will be installed: autoconf automake autopoint autotools-dev bsdextrautils debhelper debugedit dh-autoreconf dh-python dh-strip-nondeterminism dwz file gettext gettext-base groff-base intltool-debian libarchive-zip-perl libbsd0 libdebhelper-perl libdouble-conversion3 libdw1 libedit2 libelf1 libfile-stripnondeterminism-perl libicu67 libjs-jquery libmagic-mgc libmagic1 libmd0 libpipeline1 libpython3.10-minimal libpython3.10-stdlib libsigsegv2 libsub-override-perl libtool libuchardet0 libxml2 m4 man-db netbase po-debconf python-babel-localedata python3-aiofiles python3-aiosqlite python3-all python3-anyio python3-async-generator python3-attr python3-babel python3-certifi python3-chardet python3-click python3-colorama python3-databases python3-distutils python3-dnspython python3-email-validator python3-flask python3-h11 python3-httpcore python3-httpx python3-idna python3-importlib-metadata python3-iniconfig python3-itsdangerous python3-jinja2 python3-lib2to3 python3-markupsafe python3-more-itertools python3-multipart python3-packaging python3-peewee python3-pkg-resources python3-pluggy python3-py python3-pydantic python3-pyparsing python3-pytest python3-pytest-asyncio python3-requests python3-rfc3986 python3-six python3-sniffio python3-sqlalchemy python3-starlette python3-toml python3-typing-extensions python3-tz python3-ujson python3-urllib3 python3-werkzeug python3-zipp python3.10 python3.10-minimal sbuild-build-depends-fastapi-dummy 0 upgraded, 95 newly installed, 0 to remove and 3 not upgraded. Need to get 32.4 MB of archives. After this operation, 132 MB of additional disk space will be used. Get:1 copy:/<>/resolver-LHg2Wo/apt_archive ./ sbuild-build-depends-fastapi-dummy 0.invalid.0 [760 B] Get:2 http://ftpmaster.internal/ubuntu jammy/main amd64 libpython3.10-minimal amd64 3.10.1-2 [808 kB] Get:3 http://ftpmaster.internal/ubuntu jammy/main amd64 python3.10-minimal amd64 3.10.1-2 [2093 kB] Get:4 http://ftpmaster.internal/ubuntu jammy/main amd64 libmd0 amd64 1.0.4-1 [22.9 kB] Get:5 http://ftpmaster.internal/ubuntu jammy/main amd64 libbsd0 amd64 0.11.3-1ubuntu3 [44.7 kB] Get:6 http://ftpmaster.internal/ubuntu jammy/main amd64 libelf1 amd64 0.186-1 [51.4 kB] Get:7 http://ftpmaster.internal/ubuntu jammy/main amd64 libicu67 amd64 67.1-7ubuntu1 [10.1 MB] Get:8 http://ftpmaster.internal/ubuntu jammy/main amd64 libxml2 amd64 2.9.12+dfsg-5 [761 kB] Get:9 http://ftpmaster.internal/ubuntu jammy/main amd64 netbase all 6.3 [12.9 kB] Get:10 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-pkg-resources all 58.2.0-1 [130 kB] Get:11 http://ftpmaster.internal/ubuntu jammy/main amd64 bsdextrautils amd64 2.37.2-4ubuntu1 [71.1 kB] Get:12 http://ftpmaster.internal/ubuntu jammy/main amd64 libmagic-mgc amd64 1:5.41-2 [257 kB] Get:13 http://ftpmaster.internal/ubuntu jammy/main amd64 libmagic1 amd64 1:5.41-2 [87.3 kB] Get:14 http://ftpmaster.internal/ubuntu jammy/main amd64 file amd64 1:5.41-2 [21.5 kB] Get:15 http://ftpmaster.internal/ubuntu jammy/main amd64 gettext-base amd64 0.21-4ubuntu3 [36.6 kB] Get:16 http://ftpmaster.internal/ubuntu jammy/main amd64 libuchardet0 amd64 0.0.7-1build1 [76.7 kB] Get:17 http://ftpmaster.internal/ubuntu jammy/main amd64 groff-base amd64 1.22.4-8 [952 kB] Get:18 http://ftpmaster.internal/ubuntu jammy/main amd64 libedit2 amd64 3.1-20210910-1 [96.5 kB] Get:19 http://ftpmaster.internal/ubuntu jammy/main amd64 libpipeline1 amd64 1.5.5-1 [23.5 kB] Get:20 http://ftpmaster.internal/ubuntu jammy/main amd64 man-db amd64 2.9.4-4 [1179 kB] Get:21 http://ftpmaster.internal/ubuntu jammy/main amd64 libsigsegv2 amd64 2.13-1ubuntu2 [14.6 kB] Get:22 http://ftpmaster.internal/ubuntu jammy/main amd64 m4 amd64 1.4.18-5ubuntu1 [199 kB] Get:23 http://ftpmaster.internal/ubuntu jammy/main amd64 autoconf all 2.71-2 [338 kB] Get:24 http://ftpmaster.internal/ubuntu jammy/main amd64 autotools-dev all 20180224.1+nmu1 [39.4 kB] Get:25 http://ftpmaster.internal/ubuntu jammy/main amd64 automake all 1:1.16.5-1.1 [558 kB] Get:26 http://ftpmaster.internal/ubuntu jammy/main amd64 autopoint all 0.21-4ubuntu3 [422 kB] Get:27 http://ftpmaster.internal/ubuntu jammy/main amd64 libdebhelper-perl all 13.5.2ubuntu1 [66.0 kB] Get:28 http://ftpmaster.internal/ubuntu jammy/main amd64 libtool all 2.4.6-15build1 [164 kB] Get:29 http://ftpmaster.internal/ubuntu jammy/main amd64 dh-autoreconf all 20 [16.1 kB] Get:30 http://ftpmaster.internal/ubuntu jammy/main amd64 libarchive-zip-perl all 1.68-1 [90.2 kB] Get:31 http://ftpmaster.internal/ubuntu jammy/main amd64 libsub-override-perl all 0.09-2 [9532 B] Get:32 http://ftpmaster.internal/ubuntu jammy/main amd64 libfile-stripnondeterminism-perl all 1.13.0-1 [18.1 kB] Get:33 http://ftpmaster.internal/ubuntu jammy/main amd64 dh-strip-nondeterminism all 1.13.0-1 [5344 B] Get:34 http://ftpmaster.internal/ubuntu jammy/main amd64 libdw1 amd64 0.186-1 [251 kB] Get:35 http://ftpmaster.internal/ubuntu jammy/main amd64 debugedit amd64 1:5.0-4 [47.1 kB] Get:36 http://ftpmaster.internal/ubuntu jammy/main amd64 dwz amd64 0.14-1build1 [104 kB] Get:37 http://ftpmaster.internal/ubuntu jammy/main amd64 gettext amd64 0.21-4ubuntu3 [824 kB] Get:38 http://ftpmaster.internal/ubuntu jammy/main amd64 intltool-debian all 0.35.0+20060710.5 [24.9 kB] Get:39 http://ftpmaster.internal/ubuntu jammy/main amd64 po-debconf all 1.0.21+nmu1 [233 kB] Get:40 http://ftpmaster.internal/ubuntu jammy/main amd64 debhelper all 13.5.2ubuntu1 [926 kB] Get:41 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-lib2to3 all 3.9.9-3 [77.7 kB] Get:42 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-distutils all 3.9.9-3 [144 kB] Get:43 http://ftpmaster.internal/ubuntu jammy/universe amd64 dh-python all 5.20220101 [103 kB] Get:44 http://ftpmaster.internal/ubuntu jammy/universe amd64 libdouble-conversion3 amd64 3.1.5-7 [39.1 kB] Get:45 http://ftpmaster.internal/ubuntu jammy/main amd64 libjs-jquery all 3.5.1+dfsg+~3.5.5-8 [321 kB] Get:46 http://ftpmaster.internal/ubuntu jammy/main amd64 libpython3.10-stdlib amd64 3.10.1-2 [1824 kB] Get:47 http://ftpmaster.internal/ubuntu jammy/main amd64 python-babel-localedata all 2.8.0+dfsg.1-7 [4982 kB] Get:48 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-aiofiles all 0.6.0-2 [7072 B] Get:49 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-typing-extensions all 3.10.0.2-1 [35.7 kB] Get:50 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-aiosqlite all 0.16.1-3 [13.4 kB] Get:51 http://ftpmaster.internal/ubuntu jammy/main amd64 python3.10 amd64 3.10.1-2 [480 kB] Get:52 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-all amd64 3.9.7-4 [912 B] Get:53 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-idna all 3.2-2 [48.1 kB] Get:54 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-sniffio all 1.2.0-1 [6438 B] Get:55 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-anyio all 2.0.2-2 [38.5 kB] Get:56 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-async-generator all 1.10-3 [17.5 kB] Get:57 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-attr all 20.3.0-1ubuntu1 [41.0 kB] Get:58 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-tz all 2021.3-1 [33.3 kB] Get:59 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-babel all 2.8.0+dfsg.1-7 [85.1 kB] Get:60 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-certifi all 2020.6.20-1 [150 kB] Get:61 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-chardet all 4.0.0-1 [98.0 kB] Get:62 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-colorama all 0.4.4-1 [24.5 kB] Get:63 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-click all 7.1.2-1 [66.1 kB] Get:64 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-sqlalchemy all 1.3.22+ds1-1build2 [797 kB] Get:65 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-databases all 0.4.1-1 [13.5 kB] Get:66 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-dnspython all 2.1.0-1ubuntu1 [123 kB] Get:67 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-email-validator all 1.1.2-1 [15.8 kB] Get:68 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-itsdangerous all 2.0.1-1 [16.4 kB] Get:69 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-markupsafe amd64 2.0.1-2 [12.8 kB] Get:70 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-jinja2 all 3.0.1-2 [108 kB] Get:71 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-werkzeug all 2.0.2+dfsg1-1 [180 kB] Get:72 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-flask all 2.0.1-2ubuntu1 [81.5 kB] Get:73 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-h11 all 0.12.0-2 [49.0 kB] Get:74 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-httpcore all 0.13.7-1 [29.2 kB] Get:75 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-rfc3986 all 1.5.0-2 [22.6 kB] Get:76 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-httpx all 0.16.1-1 [54.8 kB] Get:77 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-more-itertools all 8.10.0-2 [47.9 kB] Get:78 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-zipp all 1.0.0-3 [5440 B] Get:79 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-importlib-metadata all 4.6.4-1 [16.2 kB] Get:80 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-iniconfig all 1.1.1-1 [5960 B] Get:81 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-six all 1.16.0-3 [12.5 kB] Get:82 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-multipart all 0.0.5-2 [27.8 kB] Get:83 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-pyparsing all 2.4.7-1 [61.4 kB] Get:84 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-packaging all 21.3-1 [30.7 kB] Get:85 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-peewee amd64 3.14.8+dfsg-1 [234 kB] Get:86 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-pluggy all 0.13.0-7.1 [19.0 kB] Get:87 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-py all 1.10.0-1 [71.9 kB] Get:88 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-pydantic all 1.8.2-1 [121 kB] Get:89 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-toml all 0.10.2-1 [16.5 kB] Get:90 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-pytest all 6.2.5-1ubuntu1 [214 kB] Get:91 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-pytest-asyncio all 0.16.0-1 [9608 B] Get:92 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-urllib3 all 1.26.5-1~exp1 [96.4 kB] Get:93 http://ftpmaster.internal/ubuntu jammy/main amd64 python3-requests all 2.25.1+dfsg-2 [47.9 kB] Get:94 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-starlette all 0.16.0-1 [44.3 kB] Get:95 http://ftpmaster.internal/ubuntu jammy/universe amd64 python3-ujson amd64 5.1.0-1 [25.9 kB] debconf: delaying package configuration, since apt-utils is not installed Fetched 32.4 MB in 0s (113 MB/s) Selecting previously unselected package libpython3.10-minimal:amd64. (Reading database ... 14211 files and directories currently installed.) Preparing to unpack .../00-libpython3.10-minimal_3.10.1-2_amd64.deb ... Unpacking libpython3.10-minimal:amd64 (3.10.1-2) ... Selecting previously unselected package python3.10-minimal. Preparing to unpack .../01-python3.10-minimal_3.10.1-2_amd64.deb ... Unpacking python3.10-minimal (3.10.1-2) ... Selecting previously unselected package libmd0:amd64. Preparing to unpack .../02-libmd0_1.0.4-1_amd64.deb ... Unpacking libmd0:amd64 (1.0.4-1) ... Selecting previously unselected package libbsd0:amd64. Preparing to unpack .../03-libbsd0_0.11.3-1ubuntu3_amd64.deb ... Unpacking libbsd0:amd64 (0.11.3-1ubuntu3) ... Selecting previously unselected package libelf1:amd64. Preparing to unpack .../04-libelf1_0.186-1_amd64.deb ... Unpacking libelf1:amd64 (0.186-1) ... Selecting previously unselected package libicu67:amd64. Preparing to unpack .../05-libicu67_67.1-7ubuntu1_amd64.deb ... Unpacking libicu67:amd64 (67.1-7ubuntu1) ... Selecting previously unselected package libxml2:amd64. Preparing to unpack .../06-libxml2_2.9.12+dfsg-5_amd64.deb ... Unpacking libxml2:amd64 (2.9.12+dfsg-5) ... Selecting previously unselected package netbase. Preparing to unpack .../07-netbase_6.3_all.deb ... Unpacking netbase (6.3) ... Selecting previously unselected package python3-pkg-resources. Preparing to unpack .../08-python3-pkg-resources_58.2.0-1_all.deb ... Unpacking python3-pkg-resources (58.2.0-1) ... Selecting previously unselected package bsdextrautils. Preparing to unpack .../09-bsdextrautils_2.37.2-4ubuntu1_amd64.deb ... Unpacking bsdextrautils (2.37.2-4ubuntu1) ... Selecting previously unselected package libmagic-mgc. Preparing to unpack .../10-libmagic-mgc_1%3a5.41-2_amd64.deb ... Unpacking libmagic-mgc (1:5.41-2) ... Selecting previously unselected package libmagic1:amd64. Preparing to unpack .../11-libmagic1_1%3a5.41-2_amd64.deb ... Unpacking libmagic1:amd64 (1:5.41-2) ... Selecting previously unselected package file. Preparing to unpack .../12-file_1%3a5.41-2_amd64.deb ... Unpacking file (1:5.41-2) ... Selecting previously unselected package gettext-base. Preparing to unpack .../13-gettext-base_0.21-4ubuntu3_amd64.deb ... Unpacking gettext-base (0.21-4ubuntu3) ... Selecting previously unselected package libuchardet0:amd64. Preparing to unpack .../14-libuchardet0_0.0.7-1build1_amd64.deb ... Unpacking libuchardet0:amd64 (0.0.7-1build1) ... Selecting previously unselected package groff-base. Preparing to unpack .../15-groff-base_1.22.4-8_amd64.deb ... Unpacking groff-base (1.22.4-8) ... Selecting previously unselected package libedit2:amd64. Preparing to unpack .../16-libedit2_3.1-20210910-1_amd64.deb ... Unpacking libedit2:amd64 (3.1-20210910-1) ... Selecting previously unselected package libpipeline1:amd64. Preparing to unpack .../17-libpipeline1_1.5.5-1_amd64.deb ... Unpacking libpipeline1:amd64 (1.5.5-1) ... Selecting previously unselected package man-db. Preparing to unpack .../18-man-db_2.9.4-4_amd64.deb ... Unpacking man-db (2.9.4-4) ... Selecting previously unselected package libsigsegv2:amd64. Preparing to unpack .../19-libsigsegv2_2.13-1ubuntu2_amd64.deb ... Unpacking libsigsegv2:amd64 (2.13-1ubuntu2) ... Selecting previously unselected package m4. Preparing to unpack .../20-m4_1.4.18-5ubuntu1_amd64.deb ... Unpacking m4 (1.4.18-5ubuntu1) ... Selecting previously unselected package autoconf. Preparing to unpack .../21-autoconf_2.71-2_all.deb ... Unpacking autoconf (2.71-2) ... Selecting previously unselected package autotools-dev. Preparing to unpack .../22-autotools-dev_20180224.1+nmu1_all.deb ... Unpacking autotools-dev (20180224.1+nmu1) ... Selecting previously unselected package automake. Preparing to unpack .../23-automake_1%3a1.16.5-1.1_all.deb ... Unpacking automake (1:1.16.5-1.1) ... Selecting previously unselected package autopoint. Preparing to unpack .../24-autopoint_0.21-4ubuntu3_all.deb ... Unpacking autopoint (0.21-4ubuntu3) ... Selecting previously unselected package libdebhelper-perl. Preparing to unpack .../25-libdebhelper-perl_13.5.2ubuntu1_all.deb ... Unpacking libdebhelper-perl (13.5.2ubuntu1) ... Selecting previously unselected package libtool. Preparing to unpack .../26-libtool_2.4.6-15build1_all.deb ... Unpacking libtool (2.4.6-15build1) ... Selecting previously unselected package dh-autoreconf. Preparing to unpack .../27-dh-autoreconf_20_all.deb ... Unpacking dh-autoreconf (20) ... Selecting previously unselected package libarchive-zip-perl. Preparing to unpack .../28-libarchive-zip-perl_1.68-1_all.deb ... Unpacking libarchive-zip-perl (1.68-1) ... Selecting previously unselected package libsub-override-perl. Preparing to unpack .../29-libsub-override-perl_0.09-2_all.deb ... Unpacking libsub-override-perl (0.09-2) ... Selecting previously unselected package libfile-stripnondeterminism-perl. Preparing to unpack .../30-libfile-stripnondeterminism-perl_1.13.0-1_all.deb ... Unpacking libfile-stripnondeterminism-perl (1.13.0-1) ... Selecting previously unselected package dh-strip-nondeterminism. Preparing to unpack .../31-dh-strip-nondeterminism_1.13.0-1_all.deb ... Unpacking dh-strip-nondeterminism (1.13.0-1) ... Selecting previously unselected package libdw1:amd64. Preparing to unpack .../32-libdw1_0.186-1_amd64.deb ... Unpacking libdw1:amd64 (0.186-1) ... Selecting previously unselected package debugedit. Preparing to unpack .../33-debugedit_1%3a5.0-4_amd64.deb ... Unpacking debugedit (1:5.0-4) ... Selecting previously unselected package dwz. Preparing to unpack .../34-dwz_0.14-1build1_amd64.deb ... Unpacking dwz (0.14-1build1) ... Selecting previously unselected package gettext. Preparing to unpack .../35-gettext_0.21-4ubuntu3_amd64.deb ... Unpacking gettext (0.21-4ubuntu3) ... Selecting previously unselected package intltool-debian. Preparing to unpack .../36-intltool-debian_0.35.0+20060710.5_all.deb ... Unpacking intltool-debian (0.35.0+20060710.5) ... Selecting previously unselected package po-debconf. Preparing to unpack .../37-po-debconf_1.0.21+nmu1_all.deb ... Unpacking po-debconf (1.0.21+nmu1) ... Selecting previously unselected package debhelper. Preparing to unpack .../38-debhelper_13.5.2ubuntu1_all.deb ... Unpacking debhelper (13.5.2ubuntu1) ... Selecting previously unselected package python3-lib2to3. Preparing to unpack .../39-python3-lib2to3_3.9.9-3_all.deb ... Unpacking python3-lib2to3 (3.9.9-3) ... Selecting previously unselected package python3-distutils. Preparing to unpack .../40-python3-distutils_3.9.9-3_all.deb ... Unpacking python3-distutils (3.9.9-3) ... Selecting previously unselected package dh-python. Preparing to unpack .../41-dh-python_5.20220101_all.deb ... Unpacking dh-python (5.20220101) ... Selecting previously unselected package libdouble-conversion3:amd64. Preparing to unpack .../42-libdouble-conversion3_3.1.5-7_amd64.deb ... Unpacking libdouble-conversion3:amd64 (3.1.5-7) ... Selecting previously unselected package libjs-jquery. Preparing to unpack .../43-libjs-jquery_3.5.1+dfsg+~3.5.5-8_all.deb ... Unpacking libjs-jquery (3.5.1+dfsg+~3.5.5-8) ... Selecting previously unselected package libpython3.10-stdlib:amd64. Preparing to unpack .../44-libpython3.10-stdlib_3.10.1-2_amd64.deb ... Unpacking libpython3.10-stdlib:amd64 (3.10.1-2) ... Selecting previously unselected package python-babel-localedata. Preparing to unpack .../45-python-babel-localedata_2.8.0+dfsg.1-7_all.deb ... Unpacking python-babel-localedata (2.8.0+dfsg.1-7) ... Selecting previously unselected package python3-aiofiles. Preparing to unpack .../46-python3-aiofiles_0.6.0-2_all.deb ... Unpacking python3-aiofiles (0.6.0-2) ... Selecting previously unselected package python3-typing-extensions. Preparing to unpack .../47-python3-typing-extensions_3.10.0.2-1_all.deb ... Unpacking python3-typing-extensions (3.10.0.2-1) ... Selecting previously unselected package python3-aiosqlite. Preparing to unpack .../48-python3-aiosqlite_0.16.1-3_all.deb ... Unpacking python3-aiosqlite (0.16.1-3) ... Selecting previously unselected package python3.10. Preparing to unpack .../49-python3.10_3.10.1-2_amd64.deb ... Unpacking python3.10 (3.10.1-2) ... Selecting previously unselected package python3-all. Preparing to unpack .../50-python3-all_3.9.7-4_amd64.deb ... Unpacking python3-all (3.9.7-4) ... Selecting previously unselected package python3-idna. Preparing to unpack .../51-python3-idna_3.2-2_all.deb ... Unpacking python3-idna (3.2-2) ... Selecting previously unselected package python3-sniffio. Preparing to unpack .../52-python3-sniffio_1.2.0-1_all.deb ... Unpacking python3-sniffio (1.2.0-1) ... Selecting previously unselected package python3-anyio. Preparing to unpack .../53-python3-anyio_2.0.2-2_all.deb ... Unpacking python3-anyio (2.0.2-2) ... Selecting previously unselected package python3-async-generator. Preparing to unpack .../54-python3-async-generator_1.10-3_all.deb ... Unpacking python3-async-generator (1.10-3) ... Selecting previously unselected package python3-attr. Preparing to unpack .../55-python3-attr_20.3.0-1ubuntu1_all.deb ... Unpacking python3-attr (20.3.0-1ubuntu1) ... Selecting previously unselected package python3-tz. Preparing to unpack .../56-python3-tz_2021.3-1_all.deb ... Unpacking python3-tz (2021.3-1) ... Selecting previously unselected package python3-babel. Preparing to unpack .../57-python3-babel_2.8.0+dfsg.1-7_all.deb ... Unpacking python3-babel (2.8.0+dfsg.1-7) ... Selecting previously unselected package python3-certifi. Preparing to unpack .../58-python3-certifi_2020.6.20-1_all.deb ... Unpacking python3-certifi (2020.6.20-1) ... Selecting previously unselected package python3-chardet. Preparing to unpack .../59-python3-chardet_4.0.0-1_all.deb ... Unpacking python3-chardet (4.0.0-1) ... Selecting previously unselected package python3-colorama. Preparing to unpack .../60-python3-colorama_0.4.4-1_all.deb ... Unpacking python3-colorama (0.4.4-1) ... Selecting previously unselected package python3-click. Preparing to unpack .../61-python3-click_7.1.2-1_all.deb ... Unpacking python3-click (7.1.2-1) ... Selecting previously unselected package python3-sqlalchemy. Preparing to unpack .../62-python3-sqlalchemy_1.3.22+ds1-1build2_all.deb ... Unpacking python3-sqlalchemy (1.3.22+ds1-1build2) ... Selecting previously unselected package python3-databases. Preparing to unpack .../63-python3-databases_0.4.1-1_all.deb ... Unpacking python3-databases (0.4.1-1) ... Selecting previously unselected package python3-dnspython. Preparing to unpack .../64-python3-dnspython_2.1.0-1ubuntu1_all.deb ... Unpacking python3-dnspython (2.1.0-1ubuntu1) ... Selecting previously unselected package python3-email-validator. Preparing to unpack .../65-python3-email-validator_1.1.2-1_all.deb ... Unpacking python3-email-validator (1.1.2-1) ... Selecting previously unselected package python3-itsdangerous. Preparing to unpack .../66-python3-itsdangerous_2.0.1-1_all.deb ... Unpacking python3-itsdangerous (2.0.1-1) ... Selecting previously unselected package python3-markupsafe. Preparing to unpack .../67-python3-markupsafe_2.0.1-2_amd64.deb ... Unpacking python3-markupsafe (2.0.1-2) ... Selecting previously unselected package python3-jinja2. Preparing to unpack .../68-python3-jinja2_3.0.1-2_all.deb ... Unpacking python3-jinja2 (3.0.1-2) ... Selecting previously unselected package python3-werkzeug. Preparing to unpack .../69-python3-werkzeug_2.0.2+dfsg1-1_all.deb ... Unpacking python3-werkzeug (2.0.2+dfsg1-1) ... Selecting previously unselected package python3-flask. Preparing to unpack .../70-python3-flask_2.0.1-2ubuntu1_all.deb ... Unpacking python3-flask (2.0.1-2ubuntu1) ... Selecting previously unselected package python3-h11. Preparing to unpack .../71-python3-h11_0.12.0-2_all.deb ... Unpacking python3-h11 (0.12.0-2) ... Selecting previously unselected package python3-httpcore. Preparing to unpack .../72-python3-httpcore_0.13.7-1_all.deb ... Unpacking python3-httpcore (0.13.7-1) ... Selecting previously unselected package python3-rfc3986. Preparing to unpack .../73-python3-rfc3986_1.5.0-2_all.deb ... Unpacking python3-rfc3986 (1.5.0-2) ... Selecting previously unselected package python3-httpx. Preparing to unpack .../74-python3-httpx_0.16.1-1_all.deb ... Unpacking python3-httpx (0.16.1-1) ... Selecting previously unselected package python3-more-itertools. Preparing to unpack .../75-python3-more-itertools_8.10.0-2_all.deb ... Unpacking python3-more-itertools (8.10.0-2) ... Selecting previously unselected package python3-zipp. Preparing to unpack .../76-python3-zipp_1.0.0-3_all.deb ... Unpacking python3-zipp (1.0.0-3) ... Selecting previously unselected package python3-importlib-metadata. Preparing to unpack .../77-python3-importlib-metadata_4.6.4-1_all.deb ... Unpacking python3-importlib-metadata (4.6.4-1) ... Selecting previously unselected package python3-iniconfig. Preparing to unpack .../78-python3-iniconfig_1.1.1-1_all.deb ... Unpacking python3-iniconfig (1.1.1-1) ... Selecting previously unselected package python3-six. Preparing to unpack .../79-python3-six_1.16.0-3_all.deb ... Unpacking python3-six (1.16.0-3) ... Selecting previously unselected package python3-multipart. Preparing to unpack .../80-python3-multipart_0.0.5-2_all.deb ... Unpacking python3-multipart (0.0.5-2) ... Selecting previously unselected package python3-pyparsing. Preparing to unpack .../81-python3-pyparsing_2.4.7-1_all.deb ... Unpacking python3-pyparsing (2.4.7-1) ... Selecting previously unselected package python3-packaging. Preparing to unpack .../82-python3-packaging_21.3-1_all.deb ... Unpacking python3-packaging (21.3-1) ... Selecting previously unselected package python3-peewee. Preparing to unpack .../83-python3-peewee_3.14.8+dfsg-1_amd64.deb ... Unpacking python3-peewee (3.14.8+dfsg-1) ... Selecting previously unselected package python3-pluggy. Preparing to unpack .../84-python3-pluggy_0.13.0-7.1_all.deb ... Unpacking python3-pluggy (0.13.0-7.1) ... Selecting previously unselected package python3-py. Preparing to unpack .../85-python3-py_1.10.0-1_all.deb ... Unpacking python3-py (1.10.0-1) ... Selecting previously unselected package python3-pydantic. Preparing to unpack .../86-python3-pydantic_1.8.2-1_all.deb ... Unpacking python3-pydantic (1.8.2-1) ... Selecting previously unselected package python3-toml. Preparing to unpack .../87-python3-toml_0.10.2-1_all.deb ... Unpacking python3-toml (0.10.2-1) ... Selecting previously unselected package python3-pytest. Preparing to unpack .../88-python3-pytest_6.2.5-1ubuntu1_all.deb ... Unpacking python3-pytest (6.2.5-1ubuntu1) ... Selecting previously unselected package python3-pytest-asyncio. Preparing to unpack .../89-python3-pytest-asyncio_0.16.0-1_all.deb ... Unpacking python3-pytest-asyncio (0.16.0-1) ... Selecting previously unselected package python3-urllib3. Preparing to unpack .../90-python3-urllib3_1.26.5-1~exp1_all.deb ... Unpacking python3-urllib3 (1.26.5-1~exp1) ... Selecting previously unselected package python3-requests. Preparing to unpack .../91-python3-requests_2.25.1+dfsg-2_all.deb ... Unpacking python3-requests (2.25.1+dfsg-2) ... Selecting previously unselected package python3-starlette. Preparing to unpack .../92-python3-starlette_0.16.0-1_all.deb ... Unpacking python3-starlette (0.16.0-1) ... Selecting previously unselected package python3-ujson:amd64. Preparing to unpack .../93-python3-ujson_5.1.0-1_amd64.deb ... Unpacking python3-ujson:amd64 (5.1.0-1) ... Selecting previously unselected package sbuild-build-depends-fastapi-dummy. Preparing to unpack .../94-sbuild-build-depends-fastapi-dummy_0.invalid.0_amd64.deb ... Unpacking sbuild-build-depends-fastapi-dummy (0.invalid.0) ... Setting up python3-pkg-resources (58.2.0-1) ... Setting up libpipeline1:amd64 (1.5.5-1) ... Setting up python3-more-itertools (8.10.0-2) ... Setting up python3-iniconfig (1.1.1-1) ... Setting up python3-sniffio (1.2.0-1) ... Setting up python3-attr (20.3.0-1ubuntu1) ... Setting up libdouble-conversion3:amd64 (3.1.5-7) ... Setting up python3-aiofiles (0.6.0-2) ... Setting up bsdextrautils (2.37.2-4ubuntu1) ... update-alternatives: using /usr/bin/write.ul to provide /usr/bin/write (write) in auto mode Setting up python3-async-generator (1.10-3) ... Setting up python3-py (1.10.0-1) ... Setting up libicu67:amd64 (67.1-7ubuntu1) ... Setting up libmagic-mgc (1:5.41-2) ... Setting up python3-colorama (0.4.4-1) ... Setting up libarchive-zip-perl (1.68-1) ... Setting up python3-peewee (3.14.8+dfsg-1) ... Setting up libdebhelper-perl (13.5.2ubuntu1) ... Setting up libmagic1:amd64 (1:5.41-2) ... Setting up gettext-base (0.21-4ubuntu3) ... Setting up python3-itsdangerous (2.0.1-1) ... Setting up file (1:5.41-2) ... Setting up python3-zipp (1.0.0-3) ... Setting up python3-click (7.1.2-1) ... Setting up python3-markupsafe (2.0.1-2) ... Setting up python3-ujson:amd64 (5.1.0-1) ... Setting up python3-tz (2021.3-1) ... Setting up python-babel-localedata (2.8.0+dfsg.1-7) ... Setting up python3-sqlalchemy (1.3.22+ds1-1build2) ... Setting up python3-six (1.16.0-3) ... Setting up autotools-dev (20180224.1+nmu1) ... Setting up python3-databases (0.4.1-1) ... Setting up python3-chardet (4.0.0-1) ... Setting up python3-pyparsing (2.4.7-1) ... Setting up python3-certifi (2020.6.20-1) ... Setting up libsigsegv2:amd64 (2.13-1ubuntu2) ... Setting up python3-idna (3.2-2) ... Setting up python3-h11 (0.12.0-2) ... Setting up libpython3.10-minimal:amd64 (3.10.1-2) ... Setting up autopoint (0.21-4ubuntu3) ... Setting up python3-typing-extensions (3.10.0.2-1) ... Setting up python3-toml (0.10.2-1) ... Setting up python3-urllib3 (1.26.5-1~exp1) ... Setting up libmd0:amd64 (1.0.4-1) ... Setting up libuchardet0:amd64 (0.0.7-1build1) ... Setting up libsub-override-perl (0.09-2) ... Setting up netbase (6.3) ... Setting up libjs-jquery (3.5.1+dfsg+~3.5.5-8) ... Setting up libbsd0:amd64 (0.11.3-1ubuntu3) ... Setting up python3-lib2to3 (3.9.9-3) ... Setting up libelf1:amd64 (0.186-1) ... Setting up python3-multipart (0.0.5-2) ... Setting up libxml2:amd64 (2.9.12+dfsg-5) ... Setting up python3-distutils (3.9.9-3) ... Setting up dh-python (5.20220101) ... Setting up libfile-stripnondeterminism-perl (1.13.0-1) ... Setting up libdw1:amd64 (0.186-1) ... Setting up gettext (0.21-4ubuntu3) ... Setting up python3-importlib-metadata (4.6.4-1) ... Setting up python3-anyio (2.0.2-2) ... Setting up libtool (2.4.6-15build1) ... Setting up python3-babel (2.8.0+dfsg.1-7) ... update-alternatives: using /usr/bin/pybabel-python3 to provide /usr/bin/pybabel (pybabel) in auto mode Setting up libedit2:amd64 (3.1-20210910-1) ... Setting up m4 (1.4.18-5ubuntu1) ... Setting up python3-starlette (0.16.0-1) ... Setting up python3.10-minimal (3.10.1-2) ... Setting up intltool-debian (0.35.0+20060710.5) ... Setting up libpython3.10-stdlib:amd64 (3.10.1-2) ... Setting up python3-jinja2 (3.0.1-2) ... Setting up python3-packaging (21.3-1) ... Setting up python3-rfc3986 (1.5.0-2) ... Setting up python3-werkzeug (2.0.2+dfsg1-1) ... Setting up python3-pydantic (1.8.2-1) ... Setting up python3-aiosqlite (0.16.1-3) ... Setting up python3-requests (2.25.1+dfsg-2) ... Setting up autoconf (2.71-2) ... Setting up python3-pluggy (0.13.0-7.1) ... Setting up dh-strip-nondeterminism (1.13.0-1) ... Setting up dwz (0.14-1build1) ... Setting up groff-base (1.22.4-8) ... Setting up python3-dnspython (2.1.0-1ubuntu1) ... Setting up debugedit (1:5.0-4) ... Setting up python3-email-validator (1.1.2-1) ... Setting up automake (1:1.16.5-1.1) ... update-alternatives: using /usr/bin/automake-1.16 to provide /usr/bin/automake (automake) in auto mode Setting up python3-httpcore (0.13.7-1) ... Setting up python3.10 (3.10.1-2) ... Setting up python3-pytest (6.2.5-1ubuntu1) ... Setting up python3-flask (2.0.1-2ubuntu1) ... Setting up po-debconf (1.0.21+nmu1) ... Setting up python3-all (3.9.7-4) ... Setting up man-db (2.9.4-4) ... Not building database; man-db/auto-update is not 'true'. Created symlink /etc/systemd/system/timers.target.wants/man-db.timer → /lib/systemd/system/man-db.timer. Setting up dh-autoreconf (20) ... Setting up python3-httpx (0.16.1-1) ... Setting up python3-pytest-asyncio (0.16.0-1) ... Setting up debhelper (13.5.2ubuntu1) ... Setting up sbuild-build-depends-fastapi-dummy (0.invalid.0) ... Processing triggers for libc-bin (2.34-0ubuntu3) ... +------------------------------------------------------------------------------+ | Build environment | +------------------------------------------------------------------------------+ Kernel: Linux 4.15.0-166-generic amd64 (x86_64) Toolchain package versions: binutils_2.37-10ubuntu1 dpkg-dev_1.21.1ubuntu11 g++-11_11.2.0-13ubuntu1 gcc-11_11.2.0-13ubuntu1 libc6-dev_2.34-0ubuntu3 libstdc++-11-dev_11.2.0-13ubuntu1 libstdc++6_12-20220106-1ubuntu1 linux-libc-dev_5.13.0-19.19 Package versions: adduser_3.118ubuntu5 advancecomp_2.1-2.1ubuntu1 apt_2.3.14 autoconf_2.71-2 automake_1:1.16.5-1.1 autopoint_0.21-4ubuntu3 autotools-dev_20180224.1+nmu1 base-files_12ubuntu2 base-passwd_3.5.52 bash_5.1-6ubuntu1 binutils_2.37-10ubuntu1 binutils-common_2.37-10ubuntu1 binutils-x86-64-linux-gnu_2.37-10ubuntu1 bsdextrautils_2.37.2-4ubuntu1 bsdutils_1:2.37.2-4ubuntu1 build-essential_12.9ubuntu2 bzip2_1.0.8-5 ca-certificates_20211016 coreutils_8.32-4ubuntu3 cpp_4:11.2.0-1ubuntu1 cpp-11_11.2.0-13ubuntu1 dash_0.5.11+git20210903+057cd650a4ed-3 debconf_1.5.79 debhelper_13.5.2ubuntu1 debianutils_5.5-1ubuntu1 debugedit_1:5.0-4 dh-autoreconf_20 dh-python_5.20220101 dh-strip-nondeterminism_1.13.0-1 diffutils_1:3.8-0ubuntu1 dpkg_1.21.1ubuntu11 dpkg-dev_1.21.1ubuntu11 dwz_0.14-1build1 e2fsprogs_1.46.5-1ubuntu1 fakeroot_1.25.3-1.1ubuntu3 file_1:5.41-2 findutils_4.8.0-1ubuntu2 g++_4:11.2.0-1ubuntu1 g++-11_11.2.0-13ubuntu1 gcc_4:11.2.0-1ubuntu1 gcc-11_11.2.0-13ubuntu1 gcc-11-base_11.2.0-13ubuntu1 gcc-12-base_12-20220106-1ubuntu1 gettext_0.21-4ubuntu3 gettext-base_0.21-4ubuntu3 gpg_2.2.27-3ubuntu1 gpg-agent_2.2.27-3ubuntu1 gpgconf_2.2.27-3ubuntu1 gpgv_2.2.27-3ubuntu1 grep_3.7-1 groff-base_1.22.4-8 gzip_1.10-4ubuntu2 hostname_3.23ubuntu1 init_1.61 init-system-helpers_1.61 intltool-debian_0.35.0+20060710.5 libacl1_2.2.53-10ubuntu2 libapparmor1_3.0.3-0ubuntu5 libapt-pkg6.0_2.3.14 libarchive-zip-perl_1.68-1 libargon2-1_0~20171227-0.2build22 libasan6_11.2.0-13ubuntu1 libassuan0_2.5.5-1 libatomic1_12-20220106-1ubuntu1 libattr1_1:2.5.1-1 libaudit-common_1:3.0-2ubuntu3 libaudit1_1:3.0-2ubuntu3 libbinutils_2.37-10ubuntu1 libblkid1_2.37.2-4ubuntu1 libbsd0_0.11.3-1ubuntu3 libbz2-1.0_1.0.8-5 libc-bin_2.34-0ubuntu3 libc-dev-bin_2.34-0ubuntu3 libc6_2.34-0ubuntu3 libc6-dev_2.34-0ubuntu3 libcap-ng0_0.7.9-2.2build2 libcap2_1:2.44-1build2 libcc1-0_12-20220106-1ubuntu1 libcom-err2_1.46.5-1ubuntu1 libcrypt-dev_1:4.4.27-1 libcrypt1_1:4.4.27-1 libcryptsetup12_2:2.4.2-1ubuntu4 libctf-nobfd0_2.37-10ubuntu1 libctf0_2.37-10ubuntu1 libdb5.3_5.3.28+dfsg1-0.8ubuntu2 libdebconfclient0_0.256ubuntu4 libdebhelper-perl_13.5.2ubuntu1 libdevmapper1.02.1_2:1.02.175-2.1ubuntu3 libdouble-conversion3_3.1.5-7 libdpkg-perl_1.21.1ubuntu11 libdw1_0.186-1 libedit2_3.1-20210910-1 libelf1_0.186-1 libexpat1_2.4.2-1 libext2fs2_1.46.5-1ubuntu1 libfakeroot_1.25.3-1.1ubuntu3 libffi8_3.4.2-1ubuntu5 libfile-stripnondeterminism-perl_1.13.0-1 libgcc-11-dev_11.2.0-13ubuntu1 libgcc-s1_12-20220106-1ubuntu1 libgcrypt20_1.9.4-3ubuntu2 libgdbm-compat4_1.22-1 libgdbm6_1.22-1 libgmp10_2:6.2.1+dfsg-1ubuntu3 libgnutls30_3.7.2-4ubuntu1 libgomp1_12-20220106-1ubuntu1 libgpg-error0_1.43-1 libgssapi-krb5-2_1.19.2-0ubuntu1 libhogweed6_3.7.3-1build1 libicu67_67.1-7ubuntu1 libidn2-0_2.3.2-2 libip4tc2_1.8.7-1ubuntu4 libisl23_0.24-2 libitm1_12-20220106-1ubuntu1 libjs-jquery_3.5.1+dfsg+~3.5.5-8 libjson-c5_0.15-2build3 libk5crypto3_1.19.2-0ubuntu1 libkeyutils1_1.6.1-2ubuntu2 libkmod2_28-1ubuntu5 libkrb5-3_1.19.2-0ubuntu1 libkrb5support0_1.19.2-0ubuntu1 liblockfile-bin_1.17-1build1 liblockfile1_1.17-1build1 liblsan0_12-20220106-1ubuntu1 liblz4-1_1.9.3-2build1 liblzma5_5.2.5-2build1 libmagic-mgc_1:5.41-2 libmagic1_1:5.41-2 libmd0_1.0.4-1 libmount1_2.37.2-4ubuntu1 libmpc3_1.2.1-1 libmpdec3_2.5.1-2build1 libmpfr6_4.1.0-3build2 libncurses6_6.3-1 libncursesw6_6.3-1 libnettle8_3.7.3-1build1 libnpth0_1.6-3build1 libnsl-dev_1.3.0-2build1 libnsl2_1.3.0-2build1 libp11-kit0_0.24.0-6 libpam-modules_1.4.0-10ubuntu2 libpam-modules-bin_1.4.0-10ubuntu2 libpam-runtime_1.4.0-10ubuntu2 libpam0g_1.4.0-10ubuntu2 libpcre2-8-0_10.39-3 libpcre3_2:8.39-13build4 libperl5.32_5.32.1-3ubuntu3 libpipeline1_1.5.5-1 libpng16-16_1.6.37-3build4 libprocps8_2:3.3.17-5ubuntu3 libpython3-stdlib_3.9.7-4 libpython3.10-minimal_3.10.1-2 libpython3.10-stdlib_3.10.1-2 libpython3.9-minimal_3.9.9-2 libpython3.9-stdlib_3.9.9-2 libquadmath0_12-20220106-1ubuntu1 libreadline8_8.1.2-1 libseccomp2_2.5.2-2ubuntu2 libselinux1_3.3-1 libsemanage-common_3.3-1 libsemanage2_3.3-1 libsepol1_3.1-1ubuntu2 libsepol2_3.3-1 libsigsegv2_2.13-1ubuntu2 libsmartcols1_2.37.2-4ubuntu1 libsqlite3-0_3.36.0-2 libss2_1.46.5-1ubuntu1 libssl1.1_1.1.1l-1ubuntu1 libssl3_3.0.0-1ubuntu1 libstdc++-11-dev_11.2.0-13ubuntu1 libstdc++6_12-20220106-1ubuntu1 libsub-override-perl_0.09-2 libsystemd0_249.5-2ubuntu3 libtasn1-6_4.18.0-4 libtinfo6_6.3-1 libtirpc-common_1.3.2-2 libtirpc-dev_1.3.2-2 libtirpc3_1.3.2-2 libtool_2.4.6-15build1 libtsan0_11.2.0-13ubuntu1 libubsan1_12-20220106-1ubuntu1 libuchardet0_0.0.7-1build1 libudev1_249.5-2ubuntu3 libunistring2_0.9.10-6 libuuid1_2.37.2-4ubuntu1 libxml2_2.9.12+dfsg-5 libxxhash0_0.8.0-2build1 libzstd1_1.4.8+dfsg-3 linux-libc-dev_5.13.0-19.19 lockfile-progs_0.1.19 login_1:4.8.1-2ubuntu1 logsave_1.46.5-1ubuntu1 lsb-base_11.1.0ubuntu3 lto-disabled-list_18 m4_1.4.18-5ubuntu1 make_4.3-4ubuntu2 man-db_2.9.4-4 mawk_1.3.4.20200120-2build1 media-types_4.0.0 mount_2.37.2-4ubuntu1 ncurses-base_6.3-1 ncurses-bin_6.3-1 netbase_6.3 openssl_3.0.0-1ubuntu1 optipng_0.7.7-2 passwd_1:4.8.1-2ubuntu1 patch_2.7.6-7build1 perl_5.32.1-3ubuntu3 perl-base_5.32.1-3ubuntu3 perl-modules-5.32_5.32.1-3ubuntu3 pinentry-curses_1.1.1-1build1 pkgbinarymangler_149 po-debconf_1.0.21+nmu1 policyrcd-script-zg2_0.1-3 procps_2:3.3.17-5ubuntu3 python-babel-localedata_2.8.0+dfsg.1-7 python3_3.9.7-4 python3-aiofiles_0.6.0-2 python3-aiosqlite_0.16.1-3 python3-all_3.9.7-4 python3-anyio_2.0.2-2 python3-async-generator_1.10-3 python3-attr_20.3.0-1ubuntu1 python3-babel_2.8.0+dfsg.1-7 python3-certifi_2020.6.20-1 python3-chardet_4.0.0-1 python3-click_7.1.2-1 python3-colorama_0.4.4-1 python3-databases_0.4.1-1 python3-distutils_3.9.9-3 python3-dnspython_2.1.0-1ubuntu1 python3-email-validator_1.1.2-1 python3-flask_2.0.1-2ubuntu1 python3-h11_0.12.0-2 python3-httpcore_0.13.7-1 python3-httpx_0.16.1-1 python3-idna_3.2-2 python3-importlib-metadata_4.6.4-1 python3-iniconfig_1.1.1-1 python3-itsdangerous_2.0.1-1 python3-jinja2_3.0.1-2 python3-lib2to3_3.9.9-3 python3-markupsafe_2.0.1-2 python3-minimal_3.9.7-4 python3-more-itertools_8.10.0-2 python3-multipart_0.0.5-2 python3-packaging_21.3-1 python3-peewee_3.14.8+dfsg-1 python3-pkg-resources_58.2.0-1 python3-pluggy_0.13.0-7.1 python3-psutil_5.8.0-2 python3-py_1.10.0-1 python3-pydantic_1.8.2-1 python3-pyparsing_2.4.7-1 python3-pytest_6.2.5-1ubuntu1 python3-pytest-asyncio_0.16.0-1 python3-requests_2.25.1+dfsg-2 python3-rfc3986_1.5.0-2 python3-six_1.16.0-3 python3-sniffio_1.2.0-1 python3-sqlalchemy_1.3.22+ds1-1build2 python3-starlette_0.16.0-1 python3-toml_0.10.2-1 python3-typing-extensions_3.10.0.2-1 python3-tz_2021.3-1 python3-ujson_5.1.0-1 python3-urllib3_1.26.5-1~exp1 python3-werkzeug_2.0.2+dfsg1-1 python3-zipp_1.0.0-3 python3.10_3.10.1-2 python3.10-minimal_3.10.1-2 python3.9_3.9.9-2 python3.9-minimal_3.9.9-2 readline-common_8.1.2-1 rpcsvc-proto_1.4.2-0ubuntu5 sbuild-build-depends-core-dummy_0.invalid.0 sbuild-build-depends-fastapi-dummy_0.invalid.0 sed_4.8-1ubuntu1 sensible-utils_0.0.17 systemd_249.5-2ubuntu3 systemd-sysv_249.5-2ubuntu3 systemd-timesyncd_249.5-2ubuntu3 sysvinit-utils_2.96-7ubuntu2 tar_1.34+dfsg-1build2 tzdata_2021e-1ubuntu1 ubuntu-keyring_2021.03.26 usrmerge_25ubuntu2 util-linux_2.37.2-4ubuntu1 xz-utils_5.2.5-2build1 zlib1g_1:1.2.11.dfsg-2ubuntu7 +------------------------------------------------------------------------------+ | Build | +------------------------------------------------------------------------------+ Unpack source ------------- gpgv: Signature made Sun Jan 31 23:29:20 2021 UTC gpgv: using RSA key B9FAD3192AF3E4A5309D9D39879F3C993801A94F gpgv: Can't check signature: No public key dpkg-source: warning: cannot verify signature ./fastapi_0.63.0-2.dsc dpkg-source: info: extracting fastapi in /<> dpkg-source: info: unpacking fastapi_0.63.0.orig.tar.gz dpkg-source: info: unpacking fastapi_0.63.0-2.debian.tar.xz dpkg-source: info: using patch list from debian/patches/series dpkg-source: info: applying PR2335.patch Check disk space ---------------- Sufficient free space for build User Environment ---------------- APT_CONFIG=/var/lib/sbuild/apt.conf DEB_BUILD_OPTIONS=noautodbgsym parallel=4 HOME=/sbuild-nonexistent LANG=C.UTF-8 LC_ALL=C.UTF-8 LOGNAME=buildd PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games SCHROOT_ALIAS_NAME=build-PACKAGEBUILD-22760933 SCHROOT_CHROOT_NAME=build-PACKAGEBUILD-22760933 SCHROOT_COMMAND=env SCHROOT_GID=2501 SCHROOT_GROUP=buildd SCHROOT_SESSION_ID=build-PACKAGEBUILD-22760933 SCHROOT_UID=2001 SCHROOT_USER=buildd SHELL=/bin/sh TERM=unknown USER=buildd V=1 dpkg-buildpackage ----------------- dpkg-buildpackage.pl: info: source package fastapi dpkg-buildpackage.pl: info: source version 0.63.0-2 dpkg-buildpackage.pl: info: source distribution unstable dpkg-source --before-build . dpkg-buildpackage.pl: info: host architecture amd64 dpkg-source: info: using options from fastapi-0.63.0/debian/source/options: --extend-diff-ignore=^[^/]+.egg-info/ fakeroot debian/rules clean dh clean --with python3 --buildsystem=pybuild debian/rules override_dh_auto_clean make[1]: Entering directory '/<>' PYBUILD_SYSTEM=custom PYBUILD_CLEAN_ARGS="{interpreter} debian/setup.py clean" dh_auto_clean install -d /<>/debian/.debhelper/generated/_source/home pybuild --clean -i python{version} -p "3.10 3.9" I: pybuild base:237: python3.10 debian/setup.py clean /<>/debian/setup.py:11: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives from distutils.core import setup /usr/lib/python3.10/distutils/dist.py:274: UserWarning: Unknown distribution option: 'install_requires' warnings.warn(msg) running clean I: pybuild base:237: python3.9 debian/setup.py clean /usr/lib/python3.9/distutils/dist.py:274: UserWarning: Unknown distribution option: 'install_requires' warnings.warn(msg) running clean rm -rf .pybuild/ find . -name \*.pyc -exec rm {} \; make[1]: Leaving directory '/<>' dh_autoreconf_clean -O--buildsystem=pybuild dh_clean -O--buildsystem=pybuild rm -f debian/debhelper-build-stamp rm -rf debian/.debhelper/ rm -f -- debian/python3-fastapi.substvars debian/files rm -fr -- debian/python3-fastapi/ debian/tmp/ find . \( \( \ \( -path .\*/.git -o -path .\*/.svn -o -path .\*/.bzr -o -path .\*/.hg -o -path .\*/CVS -o -path .\*/.pc -o -path .\*/_darcs \) -prune -o -type f -a \ \( -name '#*#' -o -name '.*~' -o -name '*~' -o -name DEADJOE \ -o -name '*.orig' -o -name '*.rej' -o -name '*.bak' \ -o -name '.*.orig' -o -name .*.rej -o -name '.SUMS' \ -o -name TAGS -o \( -path '*/.deps/*' -a -name '*.P' \) \ \) -exec rm -f {} + \) -o \ \( -type d -a -name autom4te.cache -prune -exec rm -rf {} + \) \) debian/rules build dh build --with python3 --buildsystem=pybuild dh_update_autotools_config -O--buildsystem=pybuild dh_autoreconf -O--buildsystem=pybuild dh_auto_configure -O--buildsystem=pybuild install -d /<>/debian/.debhelper/generated/_source/home pybuild --configure -i python{version} -p "3.10 3.9" W: pybuild base:266: missing command (plugin=custom, method=configure, interpreter=python3.10, version=3.10) W: pybuild base:266: missing command (plugin=custom, method=configure, interpreter=python3.9, version=3.9) dh_auto_build -O--buildsystem=pybuild pybuild --build -i python{version} -p "3.10 3.9" I: pybuild base:237: python3.10 debian/setup.py build /<>/debian/setup.py:11: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives from distutils.core import setup /usr/lib/python3.10/distutils/dist.py:274: UserWarning: Unknown distribution option: 'install_requires' warnings.warn(msg) running build running build_py creating build creating build/lib creating build/lib/fastapi copying ./fastapi/__init__.py -> build/lib/fastapi copying ./fastapi/types.py -> build/lib/fastapi copying ./fastapi/exception_handlers.py -> build/lib/fastapi copying ./fastapi/routing.py -> build/lib/fastapi copying ./fastapi/datastructures.py -> build/lib/fastapi copying ./fastapi/encoders.py -> build/lib/fastapi copying ./fastapi/utils.py -> build/lib/fastapi copying ./fastapi/websockets.py -> build/lib/fastapi copying ./fastapi/background.py -> build/lib/fastapi copying ./fastapi/staticfiles.py -> build/lib/fastapi copying ./fastapi/applications.py -> build/lib/fastapi copying ./fastapi/responses.py -> build/lib/fastapi copying ./fastapi/exceptions.py -> build/lib/fastapi copying ./fastapi/concurrency.py -> build/lib/fastapi copying ./fastapi/logger.py -> build/lib/fastapi copying ./fastapi/templating.py -> build/lib/fastapi copying ./fastapi/testclient.py -> build/lib/fastapi copying ./fastapi/requests.py -> build/lib/fastapi copying ./fastapi/params.py -> build/lib/fastapi copying ./fastapi/param_functions.py -> build/lib/fastapi creating build/lib/fastapi/dependencies copying ./fastapi/dependencies/__init__.py -> build/lib/fastapi/dependencies copying ./fastapi/dependencies/models.py -> build/lib/fastapi/dependencies copying ./fastapi/dependencies/utils.py -> build/lib/fastapi/dependencies creating build/lib/fastapi/middleware copying ./fastapi/middleware/__init__.py -> build/lib/fastapi/middleware copying ./fastapi/middleware/trustedhost.py -> build/lib/fastapi/middleware copying ./fastapi/middleware/cors.py -> build/lib/fastapi/middleware copying ./fastapi/middleware/gzip.py -> build/lib/fastapi/middleware copying ./fastapi/middleware/wsgi.py -> build/lib/fastapi/middleware copying ./fastapi/middleware/httpsredirect.py -> build/lib/fastapi/middleware creating build/lib/fastapi/openapi copying ./fastapi/openapi/__init__.py -> build/lib/fastapi/openapi copying ./fastapi/openapi/models.py -> build/lib/fastapi/openapi copying ./fastapi/openapi/utils.py -> build/lib/fastapi/openapi copying ./fastapi/openapi/constants.py -> build/lib/fastapi/openapi copying ./fastapi/openapi/docs.py -> build/lib/fastapi/openapi creating build/lib/fastapi/security copying ./fastapi/security/__init__.py -> build/lib/fastapi/security copying ./fastapi/security/oauth2.py -> build/lib/fastapi/security copying ./fastapi/security/utils.py -> build/lib/fastapi/security copying ./fastapi/security/open_id_connect_url.py -> build/lib/fastapi/security copying ./fastapi/security/api_key.py -> build/lib/fastapi/security copying ./fastapi/security/base.py -> build/lib/fastapi/security copying ./fastapi/security/http.py -> build/lib/fastapi/security copying ./fastapi/py.typed -> build/lib/fastapi I: pybuild base:237: python3.9 debian/setup.py build /usr/lib/python3.9/distutils/dist.py:274: UserWarning: Unknown distribution option: 'install_requires' warnings.warn(msg) running build running build_py debian/rules override_dh_auto_test make[1]: Entering directory '/<>' # tests/test_default_response_class.py -> ModuleNotFoundError: No module named 'orjson' # test_get_custom_response -> AssertionError: orjson must be installed to use ORJSONResponse # tests/test_tutorial/test_security/test_tutorial005.py -> ModuleNotFoundError: No module named 'jose' # tests/test_response_by_alias.py -> TypeError: Field() missing 1 required positional argument: 'default' PYBUILD_SYSTEM=custom PYBUILD_TEST_ARGS="PYTHONPATH=/<>/build/lib/ {interpreter} -m pytest tests/ --ignore=tests/test_default_response_class.py --ignore=tests/test_tutorial/test_security/test_tutorial005.py --ignore=tests/test_response_by_alias.py -k ' not test_get_custom_response'" dh_auto_test pybuild --test --test-pytest -i python{version} -p "3.10 3.9" I: pybuild base:237: PYTHONPATH=/<>/build/lib/ python3.10 -m pytest tests/ --ignore=tests/test_default_response_class.py --ignore=tests/test_tutorial/test_security/test_tutorial005.py --ignore=tests/test_response_by_alias.py -k ' not test_get_custom_response' ============================= test session starts ============================== platform linux -- Python 3.10.1, pytest-6.2.5, py-1.10.0, pluggy-0.13.0 rootdir: /<> plugins: asyncio-0.16.0, anyio-0.0.0 collected 895 items / 3 deselected / 892 selected tests/test_additional_properties.py FF [ 0%] tests/test_additional_response_extra.py FF [ 0%] tests/test_additional_responses_bad.py F [ 0%] tests/test_additional_responses_custom_model_in_callback.py F [ 0%] tests/test_additional_responses_custom_validationerror.py F [ 0%] tests/test_additional_responses_default_validationerror.py F [ 0%] tests/test_additional_responses_response_class.py F [ 1%] tests/test_additional_responses_router.py FFFF [ 1%] tests/test_application.py FFFFFFFF [ 2%] tests/test_callable_endpoint.py F [ 2%] tests/test_custom_route_class.py FFFF. [ 3%] tests/test_custom_swagger_ui_redirect.py FFF [ 3%] tests/test_datastructures.py ... [ 3%] tests/test_datetime_custom_encoder.py F [ 3%] tests/test_default_response_class_router.py FFFFFFFFFFFFFF [ 5%] tests/test_dependency_cache.py FFF [ 5%] tests/test_dependency_class.py FFFFFFFF [ 6%] tests/test_dependency_contextmanager.py FFFFFFFFFFFFFFFFFF [ 8%] tests/test_dependency_duplicates.py FFFFF [ 9%] tests/test_dependency_overrides.py FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF [ 12%] tests/test_dependency_security_overrides.py FFF [ 13%] tests/test_deprecated_openapi_prefix.py FF [ 13%] tests/test_duplicate_models_openapi.py FF [ 13%] tests/test_empty_router.py F. [ 13%] tests/test_exception_handlers.py FF [ 14%] tests/test_extra_routes.py FFFFFFFF [ 14%] tests/test_fakeasync.py . [ 15%] tests/test_filter_pydantic_sub_model.py FFF [ 15%] tests/test_forms_from_non_typing_sequences.py FFF [ 15%] tests/test_get_request_body.py FF [ 15%] tests/test_http_connection_injection.py FF [ 16%] tests/test_include_route.py F [ 16%] tests/test_include_router_defaults_overrides.py FFFFFFFFFFFFFFFFFFFFFFFF [ 18%] FFFFFFFFFFFFFFFFFFF [ 21%] tests/test_infer_param_optionality.py FFFFFFFFFF [ 22%] tests/test_inherited_custom_class.py F [ 22%] tests/test_invalid_path_param.py ....... [ 23%] tests/test_invalid_sequence_param.py .... [ 23%] tests/test_jsonable_encoder.py .............. [ 25%] tests/test_local_docs.py ..... [ 25%] tests/test_multi_body_errors.py FFFF [ 26%] tests/test_multi_query_errors.py FFF [ 26%] tests/test_multipart_installation.py .......... [ 27%] tests/test_no_swagger_ui_redirect.py FFF [ 27%] tests/test_openapi_servers.py FF [ 28%] tests/test_operations_signatures.py . [ 28%] tests/test_param_class.py FF [ 28%] tests/test_param_in_path_and_dependency.py FF [ 28%] tests/test_params_repr.py ............................... [ 32%] tests/test_path.py FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF [ 38%] FFFFFFFFFFFFFFFFFFFFFFF [ 40%] tests/test_put_no_body.py FFF [ 41%] tests/test_query.py FFFFFFFFFFFFFFFFFFFFFFFF [ 43%] tests/test_repeated_cookie_headers.py F [ 43%] tests/test_repeated_dependency_schema.py FF [ 44%] tests/test_request_body_parameters_media_type.py F [ 44%] tests/test_response_change_status_code.py F [ 44%] tests/test_response_class_no_mediatype.py F [ 44%] tests/test_response_code_no_body.py F [ 44%] tests/test_response_model_invalid.py .... [ 44%] tests/test_response_model_sub_types.py FF [ 45%] tests/test_router_events.py F [ 45%] tests/test_router_prefix_with_template.py F [ 45%] tests/test_security_api_key_cookie.py FFF [ 45%] tests/test_security_api_key_cookie_optional.py FFF [ 46%] tests/test_security_api_key_header.py FFF [ 46%] tests/test_security_api_key_header_optional.py FFF [ 46%] tests/test_security_api_key_query.py FFF [ 47%] tests/test_security_api_key_query_optional.py FFF [ 47%] tests/test_security_http_base.py FFF [ 47%] tests/test_security_http_base_optional.py FFF [ 48%] tests/test_security_http_basic_optional.py FFFFF [ 48%] tests/test_security_http_basic_realm.py FFFFF [ 49%] tests/test_security_http_bearer.py FFFF [ 49%] tests/test_security_http_bearer_optional.py FFFF [ 50%] tests/test_security_http_digest.py FFFF [ 50%] tests/test_security_http_digest_optional.py FFFF [ 51%] tests/test_security_oauth2.py FFFFFFFF [ 51%] tests/test_security_oauth2_authorization_code_bearer.py FFFF [ 52%] tests/test_security_oauth2_optional.py FFFFFFFF [ 53%] tests/test_security_oauth2_password_bearer_optional.py FFFF [ 53%] tests/test_security_openid_connect.py FFFF [ 54%] tests/test_security_openid_connect_optional.py FFFF [ 54%] tests/test_serialize_response.py FFF [ 54%] tests/test_serialize_response_dataclass.py FFF [ 55%] tests/test_serialize_response_model.py FFFFFFFF [ 56%] tests/test_skip_defaults.py FFFFF [ 56%] tests/test_starlette_exception.py FFFFF [ 57%] tests/test_starlette_urlconvertors.py FFF. [ 57%] tests/test_sub_callbacks.py FF [ 57%] tests/test_swagger_ui_init_oauth.py FF [ 58%] tests/test_union_body.py FFF [ 58%] tests/test_union_inherited_body.py FFF [ 58%] tests/test_validate_response.py FFF [ 59%] tests/test_validate_response_dataclass.py FFF [ 59%] tests/test_validate_response_recursive.py F [ 59%] tests/test_ws_router.py FFFFFF [ 60%] tests/test_modules_same_name_body/test_main.py FFFFF [ 60%] tests/test_tutorial/test_additional_responses/test_tutorial001.py FFF [ 61%] tests/test_tutorial/test_additional_responses/test_tutorial002.py FFF [ 61%] tests/test_tutorial/test_additional_responses/test_tutorial003.py FFF [ 61%] tests/test_tutorial/test_additional_responses/test_tutorial004.py FFF [ 62%] tests/test_tutorial/test_additional_status_codes/test_tutorial001.py FF [ 62%] tests/test_tutorial/test_advanced_middleware/test_tutorial001.py F [ 62%] tests/test_tutorial/test_advanced_middleware/test_tutorial002.py F [ 62%] tests/test_tutorial/test_advanced_middleware/test_tutorial003.py F [ 62%] tests/test_tutorial/test_async_sql_databases/test_tutorial001.py FF [ 63%] tests/test_tutorial/test_async_tests/test_main.py FF [ 63%] tests/test_tutorial/test_background_tasks/test_tutorial001.py F [ 63%] tests/test_tutorial/test_background_tasks/test_tutorial002.py F [ 63%] tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py FF [ 63%] tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py FF [ 63%] tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py FF [ 64%] tests/test_tutorial/test_behind_a_proxy/test_tutorial004.py FF [ 64%] tests/test_tutorial/test_bigger_applications/test_main.py FFFFFFFFFFFFFF [ 65%] FFFFFFFFF [ 66%] tests/test_tutorial/test_body/test_tutorial001.py FFFFFFFFFF [ 68%] tests/test_tutorial/test_body_fields/test_tutorial001.py FFFF [ 68%] tests/test_tutorial/test_body_multiple_params/test_tutorial001.py FFFFF [ 69%] tests/test_tutorial/test_body_multiple_params/test_tutorial003.py FFFF [ 69%] tests/test_tutorial/test_body_nested_models/test_tutorial009.py FFF [ 69%] tests/test_tutorial/test_body_updates/test_tutorial001.py FFF [ 70%] tests/test_tutorial/test_conditional_openapi/test_tutorial001.py FF [ 70%] tests/test_tutorial/test_cookie_params/test_tutorial001.py FFFFF [ 70%] tests/test_tutorial/test_cors/test_tutorial001.py F [ 71%] tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py FF [ 71%] F [ 71%] tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py FF [ 71%] [ 71%] tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py FF [ 71%] [ 71%] tests/test_tutorial/test_custom_response/test_tutorial001.py F [ 71%] tests/test_tutorial/test_custom_response/test_tutorial001b.py F [ 72%] tests/test_tutorial/test_custom_response/test_tutorial004.py F [ 72%] tests/test_tutorial/test_custom_response/test_tutorial005.py FF [ 72%] tests/test_tutorial/test_custom_response/test_tutorial006.py F [ 72%] tests/test_tutorial/test_custom_response/test_tutorial007.py F [ 72%] tests/test_tutorial/test_custom_response/test_tutorial008.py F [ 72%] tests/test_tutorial/test_dependencies/test_tutorial001.py FFFFFFF [ 73%] tests/test_tutorial/test_dependencies/test_tutorial004.py FFFFFFF [ 74%] tests/test_tutorial/test_dependencies/test_tutorial006.py FFFFF [ 74%] tests/test_tutorial/test_dependencies/test_tutorial012.py FFFFFFFFF [ 75%] tests/test_tutorial/test_events/test_tutorial001.py F [ 76%] tests/test_tutorial/test_events/test_tutorial002.py F [ 76%] tests/test_tutorial/test_extending_openapi/test_tutorial001.py FF [ 76%] tests/test_tutorial/test_extending_openapi/test_tutorial002.py EEEE [ 76%] tests/test_tutorial/test_extra_data_types/test_tutorial001.py FF [ 77%] tests/test_tutorial/test_extra_models/test_tutorial003.py FFF [ 77%] tests/test_tutorial/test_extra_models/test_tutorial004.py FF [ 77%] tests/test_tutorial/test_extra_models/test_tutorial005.py FF [ 77%] tests/test_tutorial/test_first_steps/test_tutorial001.py FFF [ 78%] tests/test_tutorial/test_handling_errors/test_tutorial001.py FFF [ 78%] tests/test_tutorial/test_handling_errors/test_tutorial002.py FFF [ 78%] tests/test_tutorial/test_handling_errors/test_tutorial003.py FFF [ 79%] tests/test_tutorial/test_handling_errors/test_tutorial004.py FFFF [ 79%] tests/test_tutorial/test_handling_errors/test_tutorial005.py FFF [ 79%] tests/test_tutorial/test_handling_errors/test_tutorial006.py FFFF [ 80%] tests/test_tutorial/test_header_params/test_tutorial001.py FFFF [ 80%] tests/test_tutorial/test_metadata/test_tutorial001.py FF [ 81%] tests/test_tutorial/test_metadata/test_tutorial004.py FF [ 81%] tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py FF. [ 81%] tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial001.py F [ 81%] F [ 81%] tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial002.py F [ 81%] F [ 82%] tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial003.py F [ 82%] F [ 82%] tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py F [ 82%] F [ 82%] tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py F [ 82%] F [ 82%] tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py F [ 82%] FFF [ 83%] tests/test_tutorial/test_path_params/test_tutorial004.py FFF [ 83%] tests/test_tutorial/test_path_params/test_tutorial005.py FFFFF [ 84%] tests/test_tutorial/test_query_params/test_tutorial005.py FFFF [ 84%] tests/test_tutorial/test_query_params/test_tutorial006.py FFF [ 84%] tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py F [ 84%] FFFF [ 85%] tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py F [ 85%] FF [ 85%] tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py F [ 85%] FF [ 86%] tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py F [ 86%] FF [ 86%] tests/test_tutorial/test_request_files/test_tutorial001.py FFFFFF [ 87%] tests/test_tutorial/test_request_files/test_tutorial002.py FFFFFF [ 87%] tests/test_tutorial/test_request_forms/test_tutorial001.py FFFFFF [ 88%] tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py FFF [ 88%] FFF [ 89%] tests/test_tutorial/test_response_change_status_code/test_tutorial001.py F [ 89%] [ 89%] tests/test_tutorial/test_response_cookies/test_tutorial001.py F [ 89%] tests/test_tutorial/test_response_cookies/test_tutorial002.py F [ 89%] tests/test_tutorial/test_response_headers/test_tutorial001.py F [ 89%] tests/test_tutorial/test_response_headers/test_tutorial002.py F [ 89%] tests/test_tutorial/test_response_model/test_tutorial003.py FF [ 89%] tests/test_tutorial/test_response_model/test_tutorial004.py FFFF [ 90%] tests/test_tutorial/test_response_model/test_tutorial005.py FFF [ 90%] tests/test_tutorial/test_response_model/test_tutorial006.py FFF [ 91%] tests/test_tutorial/test_security/test_tutorial001.py FFFF [ 91%] tests/test_tutorial/test_security/test_tutorial003.py FFFFFFFFF [ 92%] tests/test_tutorial/test_security/test_tutorial006.py FFFFF [ 93%] tests/test_tutorial/test_settings/test_app02.py F [ 93%] tests/test_tutorial/test_sql_databases/test_sql_databases.py EEEEEEE [ 93%] tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py E [ 94%] EEEEEE [ 94%] tests/test_tutorial/test_sql_databases/test_testing_databases.py F [ 94%] tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py E [ 94%] EEEEEEE [ 95%] tests/test_tutorial/test_sub_applications/test_tutorial001.py FFFF [ 96%] tests/test_tutorial/test_templates/test_tutorial001.py F [ 96%] tests/test_tutorial/test_testing/test_main.py FFF [ 96%] tests/test_tutorial/test_testing/test_tutorial001.py FFF [ 96%] tests/test_tutorial/test_testing/test_tutorial002.py FFFF [ 97%] tests/test_tutorial/test_testing/test_tutorial003.py FF [ 97%] tests/test_tutorial/test_testing_dependencies/test_tutorial001.py FFFFFF [ 98%] FFFF [ 98%] tests/test_tutorial/test_websockets/test_tutorial001.py FF [ 98%] tests/test_tutorial/test_websockets/test_tutorial002.py FFFFFF [ 99%] tests/test_tutorial/test_websockets/test_tutorial003.py F [ 99%] tests/test_tutorial/test_wsgi/test_tutorial001.py FF [100%] ==================================== ERRORS ==================================== ____________________ ERROR at setup of test_swagger_ui_html ____________________ @pytest.fixture(scope="module") def client(): static_dir: Path = Path(os.getcwd()) / "static" print(static_dir) static_dir.mkdir(exist_ok=True) from docs_src.extending_openapi.tutorial002 import app > with TestClient(app) as client: tests/test_tutorial/test_extending_openapi/test_tutorial002.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ---------------------------- Captured stdout setup ----------------------------- /<>/static ____________ ERROR at setup of test_swagger_ui_oauth2_redirect_html ____________ @pytest.fixture(scope="module") def client(): static_dir: Path = Path(os.getcwd()) / "static" print(static_dir) static_dir.mkdir(exist_ok=True) from docs_src.extending_openapi.tutorial002 import app > with TestClient(app) as client: tests/test_tutorial/test_extending_openapi/test_tutorial002.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_redoc_html _______________________ @pytest.fixture(scope="module") def client(): static_dir: Path = Path(os.getcwd()) / "static" print(static_dir) static_dir.mkdir(exist_ok=True) from docs_src.extending_openapi.tutorial002 import app > with TestClient(app) as client: tests/test_tutorial/test_extending_openapi/test_tutorial002.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError __________________________ ERROR at setup of test_api __________________________ @pytest.fixture(scope="module") def client(): static_dir: Path = Path(os.getcwd()) / "static" print(static_dir) static_dir.mkdir(exist_ok=True) from docs_src.extending_openapi.tutorial002 import app > with TestClient(app) as client: tests/test_tutorial/test_extending_openapi/test_tutorial002.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_openapi_schema _____________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_user ______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_user ________________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_inexistent_user ____________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_users _______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_item ______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_read_items _______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_openapi_schema _____________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_user ______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_user ________________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_inexistent_user ____________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_users _______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_item ______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_read_items _______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_openapi_schema _____________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_user ______________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_user ________________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_inexistent_user ____________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_users _______________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _____________________ ERROR at setup of test_get_slowusers _____________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_item ______________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_read_items _______________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError =================================== FAILURES =================================== ______________________ test_additional_properties_schema _______________________ def test_additional_properties_schema(): > response = client.get("/openapi.json") tests/test_additional_properties.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_additional_properties_post ________________________ def test_additional_properties_post(): > response = client.post("/foo", json={"items": {"foo": 1, "bar": 2}}) tests/test_additional_properties.py:108: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/foo', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'31'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_response_extra.py:44: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/items/") tests/test_additional_response_extra.py:50: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): with pytest.raises(ValueError): > client.get("/openapi.json") tests/test_additional_responses_bad.py:40: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_responses_custom_model_in_callback.py:136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_responses_custom_validationerror.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_responses_default_validationerror.py:83: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_responses_response_class.py:115: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_responses_router.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________________ test_a ____________________________________ def test_a(): > response = client.get("/a") tests/test_additional_responses_router.py:97: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________________ test_b ____________________________________ def test_b(): > response = client.get("/b") tests/test_additional_responses_router.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/b', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________________ test_c ____________________________________ def test_c(): > response = client.get("/c") tests/test_additional_responses_router.py:109: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/c', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/api_route-200-expected_response0] _______________ path = '/api_route', expected_status = 200 expected_response = {'message': 'Hello World'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/api_route", 200, {"message": "Hello World"}), ("/non_decorated_route", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_application.py:1136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/api_route', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/non_decorated_route-200-expected_response1] __________ path = '/non_decorated_route', expected_status = 200 expected_response = {'message': 'Hello World'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/api_route", 200, {"message": "Hello World"}), ("/non_decorated_route", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_application.py:1136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/non_decorated_route' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_get_path[/nonexistent-404-expected_response2] ______________ path = '/nonexistent', expected_status = 404 expected_response = {'detail': 'Not Found'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/api_route", 200, {"message": "Hello World"}), ("/non_decorated_route", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_application.py:1136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/nonexistent', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/openapi.json-200-expected_response3] ______________ path = '/openapi.json', expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type...Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Get Bool Id'}}, ...}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/api_route", 200, {"message": "Hello World"}), ("/non_decorated_route", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_application.py:1136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_swagger_ui ________________________________ def test_swagger_ui(): > response = client.get("/docs") tests/test_application.py:1142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_swagger_ui_oauth2_redirect ________________________ def test_swagger_ui_oauth2_redirect(): > response = client.get("/docs/oauth2-redirect") tests/test_application.py:1153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs/oauth2-redirect' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_redoc __________________________________ def test_redoc(): > response = client.get("/redoc") tests/test_application.py:1160: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/redoc', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_enum_status_code_response ________________________ def test_enum_status_code_response(): > response = client.get("/enum-status-code") tests/test_application.py:1167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/enum-status-code', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_partial _________________________________ def test_partial(): > response = client.get("/?q=bar") tests/test_callable_endpoint.py:23: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = 'q=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/a-200-expected_response0] ___________________ path = '/a', expected_status = 200, expected_response = {'msg': 'A'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/a", 200, {"msg": "A"}), ("/a/b", 200, {"msg": "B"}), ("/a/b/c", 200, {"msg": "C"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_custom_route_class.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/a/b-200-expected_response1] __________________ path = '/a/b', expected_status = 200, expected_response = {'msg': 'B'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/a", 200, {"msg": "A"}), ("/a/b", 200, {"msg": "B"}), ("/a/b/c", 200, {"msg": "C"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_custom_route_class.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a/b', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/a/b/c-200-expected_response2] _________________ path = '/a/b/c', expected_status = 200, expected_response = {'msg': 'C'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/a", 200, {"msg": "A"}), ("/a/b", 200, {"msg": "B"}), ("/a/b/c", 200, {"msg": "C"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_custom_route_class.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a/b/c', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/openapi.json-200-expected_response3] ______________ path = '/openapi.json', expected_status = 200 expected_response = {'info': {'title': 'FastAPI', 'version': '0.1.0'}, 'openapi': '3.0.2', 'paths': {'/a/': {'get': {'operationId': 'get_a...t_c_a_b_c__get', 'responses': {'200': {'content': {...}, 'description': 'Successful Response'}}, 'summary': 'Get C'}}}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/a", 200, {"msg": "A"}), ("/a/b", 200, {"msg": "B"}), ("/a/b/c", 200, {"msg": "C"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_custom_route_class.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_swagger_ui ________________________________ def test_swagger_ui(): > response = client.get("/docs") tests/test_custom_swagger_ui_redirect.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_swagger_ui_oauth2_redirect ________________________ def test_swagger_ui_oauth2_redirect(): > response = client.get(swagger_ui_oauth2_redirect_url) tests/test_custom_swagger_ui_redirect.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs/redirect', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_response _________________________________ def test_response(): > response = client.get("/items/") tests/test_custom_swagger_ui_redirect.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_dt ____________________________________ def test_dt(): > with client: tests/test_datetime_custom_encoder.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________________ test_app ___________________________________ def test_app(): > with client: tests/test_default_response_class_router.py:112: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________________ test_app_override _______________________________ def test_app_override(): > with client: tests/test_default_response_class_router.py:119: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ________________________________ test_router_a _________________________________ def test_router_a(): > with client: tests/test_default_response_class_router.py:126: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________________ test_router_a_override ____________________________ def test_router_a_override(): > with client: tests/test_default_response_class_router.py:133: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________________ test_router_a_a ________________________________ def test_router_a_a(): > with client: tests/test_default_response_class_router.py:140: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________ test_router_a_a_override ___________________________ def test_router_a_a_override(): > with client: tests/test_default_response_class_router.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________________ test_router_a_b ________________________________ def test_router_a_b(): > with client: tests/test_default_response_class_router.py:154: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________ test_router_a_b_override ___________________________ def test_router_a_b_override(): > with client: tests/test_default_response_class_router.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ________________________________ test_router_b _________________________________ def test_router_b(): > with client: tests/test_default_response_class_router.py:168: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________________ test_router_b_override ____________________________ def test_router_b_override(): > with client: tests/test_default_response_class_router.py:175: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________________ test_router_b_a ________________________________ def test_router_b_a(): > with client: tests/test_default_response_class_router.py:182: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________ test_router_b_a_override ___________________________ def test_router_b_a_override(): > with client: tests/test_default_response_class_router.py:189: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________________ test_router_b_a_c _______________________________ def test_router_b_a_c(): > with client: tests/test_default_response_class_router.py:196: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError __________________________ test_router_b_a_c_override __________________________ def test_router_b_a_c_override(): > with client: tests/test_default_response_class_router.py:203: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _____________________________ test_normal_counter ______________________________ def test_normal_counter(): counter_holder["counter"] = 0 > response = client.get("/counter/") tests/test_dependency_cache.py:43: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/counter/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_sub_counter _______________________________ def test_sub_counter(): counter_holder["counter"] = 0 > response = client.get("/sub-counter/") tests/test_dependency_cache.py:53: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sub-counter/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_sub_counter_no_cache ___________________________ def test_sub_counter_no_cache(): counter_holder["counter"] = 0 > response = client.get("/sub-counter-no-cache/") tests/test_dependency_cache.py:63: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sub-counter-no-cache/' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_class_dependency[/callable-dependency-callable-dependency] ________ route = '/callable-dependency', value = 'callable-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/callable-dependency' query = 'value=callable-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_class_dependency[/callable-gen-dependency-callable-gen-dependency] ____ route = '/callable-gen-dependency', value = 'callable-gen-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/callable-gen-dependency' query = 'value=callable-gen-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/async-callable-dependency-async-callable-dependency] __ route = '/async-callable-dependency', value = 'async-callable-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/async-callable-dependency' query = 'value=async-callable-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/async-callable-gen-dependency-async-callable-gen-dependency] _ route = '/async-callable-gen-dependency' value = 'async-callable-gen-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/async-callable-gen-dependency' query = 'value=async-callable-gen-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/synchronous-method-dependency-synchronous-method-dependency] _ route = '/synchronous-method-dependency' value = 'synchronous-method-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/synchronous-method-dependency' query = 'value=synchronous-method-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/synchronous-method-gen-dependency-synchronous-method-gen-dependency] _ route = '/synchronous-method-gen-dependency' value = 'synchronous-method-gen-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/synchronous-method-gen-dependency' query = 'value=synchronous-method-gen-dependency', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/asynchronous-method-dependency-asynchronous-method-dependency] _ route = '/asynchronous-method-dependency' value = 'asynchronous-method-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/asynchronous-method-dependency' query = 'value=asynchronous-method-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/asynchronous-method-gen-dependency-asynchronous-method-gen-dependency] _ route = '/asynchronous-method-gen-dependency' value = 'asynchronous-method-gen-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/asynchronous-method-gen-dependency' query = 'value=asynchronous-method-gen-dependency', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_async_state _______________________________ def test_async_state(): assert state["/async"] == "asyncgen not started" > response = client.get("/async") tests/test_dependency_contextmanager.py:208: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/async', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_sync_state ________________________________ def test_sync_state(): assert state["/sync"] == "generator not started" > response = client.get("/sync") tests/test_dependency_contextmanager.py:216: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_async_raise_other ____________________________ def test_async_raise_other(): assert state["/async_raise"] == "asyncgen raise not started" with pytest.raises(OtherDependencyError): > client.get("/async_raise_other") tests/test_dependency_contextmanager.py:225: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/async_raise_other', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_sync_raise_other _____________________________ def test_sync_raise_other(): assert state["/sync_raise"] == "generator raise not started" with pytest.raises(OtherDependencyError): > client.get("/sync_raise_other") tests/test_dependency_contextmanager.py:233: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_raise_other', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_async_raise _______________________________ def test_async_raise(): > response = client.get("/async_raise") tests/test_dependency_contextmanager.py:239: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/async_raise', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_context_b ________________________________ def test_context_b(): > response = client.get("/context_b") tests/test_dependency_contextmanager.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/context_b', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_context_b_raise _____________________________ def test_context_b_raise(): with pytest.raises(OtherDependencyError): > client.get("/context_b_raise") tests/test_dependency_contextmanager.py:257: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/context_b_raise', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_background_tasks _____________________________ def test_background_tasks(): > response = client.get("/context_b_bg") tests/test_dependency_contextmanager.py:263: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/context_b_bg', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_sync_raise ________________________________ def test_sync_raise(): > response = client.get("/sync_raise") tests/test_dependency_contextmanager.py:274: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_raise', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_sync_async_state _____________________________ def test_sync_async_state(): > response = client.get("/sync_async") tests/test_dependency_contextmanager.py:282: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_async', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_sync_sync_state _____________________________ def test_sync_sync_state(): > response = client.get("/sync_sync") tests/test_dependency_contextmanager.py:289: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_sync', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_sync_async_raise_other __________________________ def test_sync_async_raise_other(): with pytest.raises(OtherDependencyError): > client.get("/sync_async_raise_other") tests/test_dependency_contextmanager.py:297: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_async_raise_other' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_sync_sync_raise_other __________________________ def test_sync_sync_raise_other(): with pytest.raises(OtherDependencyError): > client.get("/sync_sync_raise_other") tests/test_dependency_contextmanager.py:304: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_sync_raise_other' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_sync_async_raise _____________________________ def test_sync_async_raise(): > response = client.get("/sync_async_raise") tests/test_dependency_contextmanager.py:310: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_async_raise', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_sync_sync_raise _____________________________ def test_sync_sync_raise(): > response = client.get("/sync_sync_raise") tests/test_dependency_contextmanager.py:318: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_sync_raise', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_sync_context_b ______________________________ def test_sync_context_b(): > response = client.get("/sync_context_b") tests/test_dependency_contextmanager.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_context_b', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_sync_context_b_raise ___________________________ def test_sync_context_b_raise(): with pytest.raises(OtherDependencyError): > client.get("/sync_context_b_raise") tests/test_dependency_contextmanager.py:336: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_context_b_raise' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_sync_background_tasks __________________________ def test_sync_background_tasks(): > response = client.get("/sync_context_b_bg") tests/test_dependency_contextmanager.py:342: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_context_b_bg', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_dependency_duplicates.py:192: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_no_duplicates_invalid __________________________ def test_no_duplicates_invalid(): > response = client.post("/no-duplicates", json={"item": {"data": "myitem"}}) tests/test_dependency_duplicates.py:198: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/no-duplicates', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'28'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_no_duplicates ______________________________ def test_no_duplicates(): > response = client.post( "/no-duplicates", json={"item": {"data": "myitem"}, "item2": {"data": "myitem2"}}, ) tests/test_dependency_duplicates.py:212: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/no-duplicates', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'58'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_duplicates ________________________________ def test_duplicates(): > response = client.post("/with-duplicates", json={"data": "myitem"}) tests/test_dependency_duplicates.py:221: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/with-duplicates', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'18'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_sub_duplicates ______________________________ def test_sub_duplicates(): > response = client.post("/with-duplicates-sub", json={"data": "myitem"}) tests/test_dependency_duplicates.py:227: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/with-duplicates-sub' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'18'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_normal_app[/main-depends/-422-expected0] _________________ url = '/main-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'q'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_normal_app[/main-depends/?q=foo-200-expected1] ______________ url = '/main-depends/?q=foo', status_code = 200 expected = {'in': 'main-depends', 'params': {'limit': 100, 'q': 'foo', 'skip': 0}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____ test_normal_app[/main-depends/?q=foo&skip=100&limit=200-200-expected2] ____ url = '/main-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'main-depends', 'params': {'limit': 200, 'q': 'foo', 'skip': 100}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_normal_app[/decorator-depends/-422-expected3] ______________ url = '/decorator-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'q'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_normal_app[/decorator-depends/?q=foo-200-expected4] ___________ url = '/decorator-depends/?q=foo', status_code = 200 expected = {'in': 'decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_normal_app[/decorator-depends/?q=foo&skip=100&limit=200-200-expected5] __ url = '/decorator-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_normal_app[/router-depends/-422-expected6] ________________ url = '/router-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'q'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_normal_app[/router-depends/?q=foo-200-expected7] _____________ url = '/router-depends/?q=foo', status_code = 200 expected = {'in': 'router-depends', 'params': {'limit': 100, 'q': 'foo', 'skip': 0}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_normal_app[/router-depends/?q=foo&skip=100&limit=200-200-expected8] ___ url = '/router-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'router-depends', 'params': {'limit': 200, 'q': 'foo', 'skip': 100}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_normal_app[/router-decorator-depends/-422-expected9] ___________ url = '/router-decorator-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'q'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_normal_app[/router-decorator-depends/?q=foo-200-expected10] _______ url = '/router-decorator-depends/?q=foo', status_code = 200 expected = {'in': 'router-decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_normal_app[/router-decorator-depends/?q=foo&skip=100&limit=200-200-expected11] _ url = '/router-decorator-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'router-decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_override_simple[/main-depends/-200-expected0] ______________ url = '/main-depends/', status_code = 200 expected = {'in': 'main-depends', 'params': {'limit': 10, 'q': None, 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_override_simple[/main-depends/?q=foo-200-expected1] ___________ url = '/main-depends/?q=foo', status_code = 200 expected = {'in': 'main-depends', 'params': {'limit': 10, 'q': 'foo', 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_override_simple[/main-depends/?q=foo&skip=100&limit=200-200-expected2] __ url = '/main-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'main-depends', 'params': {'limit': 10, 'q': 'foo', 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_override_simple[/decorator-depends/-200-expected3] ____________ url = '/decorator-depends/', status_code = 200 expected = {'in': 'decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_override_simple[/router-depends/-200-expected4] _____________ url = '/router-depends/', status_code = 200 expected = {'in': 'router-depends', 'params': {'limit': 10, 'q': None, 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_override_simple[/router-depends/?q=foo-200-expected5] __________ url = '/router-depends/?q=foo', status_code = 200 expected = {'in': 'router-depends', 'params': {'limit': 10, 'q': 'foo', 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_override_simple[/router-depends/?q=foo&skip=100&limit=200-200-expected6] _ url = '/router-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'router-depends', 'params': {'limit': 10, 'q': 'foo', 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_override_simple[/router-decorator-depends/-200-expected7] ________ url = '/router-decorator-depends/', status_code = 200 expected = {'in': 'router-decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_override_with_sub[/main-depends/-422-expected0] _____________ url = '/main-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_override_with_sub[/main-depends/?q=foo-422-expected1] __________ url = '/main-depends/?q=foo', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_override_with_sub[/main-depends/?k=bar-200-expected2] __________ url = '/main-depends/?k=bar', status_code = 200 expected = {'in': 'main-depends', 'params': {'k': 'bar'}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = 'k=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_override_with_sub[/decorator-depends/-422-expected3] ___________ url = '/decorator-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_override_with_sub[/decorator-depends/?q=foo-422-expected4] ________ url = '/decorator-depends/?q=foo', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_override_with_sub[/decorator-depends/?k=bar-200-expected5] ________ url = '/decorator-depends/?k=bar', status_code = 200 expected = {'in': 'decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/' query = 'k=bar', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_override_with_sub[/router-depends/-422-expected6] ____________ url = '/router-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_override_with_sub[/router-depends/?q=foo-422-expected7] _________ url = '/router-depends/?q=foo', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_override_with_sub[/router-depends/?k=bar-200-expected8] _________ url = '/router-depends/?k=bar', status_code = 200 expected = {'in': 'router-depends', 'params': {'k': 'bar'}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'k=bar', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_override_with_sub[/router-decorator-depends/-422-expected9] _______ url = '/router-decorator-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_override_with_sub[/router-decorator-depends/?q=foo-422-expected10] ____ url = '/router-decorator-depends/?q=foo', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_override_with_sub[/router-decorator-depends/?k=bar-200-expected11] ____ url = '/router-decorator-depends/?k=bar', status_code = 200 expected = {'in': 'router-decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = 'k=bar', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_normal __________________________________ def test_normal(): > response = client.get("/user") tests/test_dependency_security_overrides.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/user', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_override_data ______________________________ def test_override_data(): app.dependency_overrides[get_data] = get_data_override > response = client.get("/user") tests/test_dependency_security_overrides.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/user', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_override_security ____________________________ def test_override_security(): app.dependency_overrides[get_user] = get_user_override > response = client.get("/user") tests/test_dependency_security_overrides.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/user', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_deprecated_openapi_prefix.py:36: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_deprecated_openapi_prefix.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_duplicate_models_openapi.py:74: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_get_api_route ______________________________ def test_get_api_route(): > response = client.get("/") tests/test_duplicate_models_openapi.py:80: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_use_empty ________________________________ def test_use_empty(): > with client: tests/test_empty_router.py:22: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _________________________ test_override_http_exception _________________________ def test_override_http_exception(): > response = client.get("/http-exception") tests/test_exception_handlers.py:36: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/http-exception', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_override_request_validation_exception __________________ def test_override_request_validation_exception(): > response = client.get("/request-validation/invalid") tests/test_exception_handlers.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/request-validation/invalid' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_extra_routes.py:318: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_get_api_route ______________________________ def test_get_api_route(): > response = client.get("/items/foo") tests/test_extra_routes.py:324: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_get_api_route_not_decorated _______________________ def test_get_api_route_not_decorated(): > response = client.get("/items-not-decorated/foo") tests/test_extra_routes.py:330: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items-not-decorated/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_delete __________________________________ def test_delete(): > response = client.delete("/items/foo", json={"name": "Foo"}) tests/test_extra_routes.py:336: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:624: in delete return self.request('DELETE', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_head ___________________________________ def test_head(): > response = client.head("/items/foo") tests/test_extra_routes.py:342: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:577: in head return self.request('HEAD', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_options _________________________________ def test_options(): > response = client.options("/items/foo") tests/test_extra_routes.py:348: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:566: in options return self.request('OPTIONS', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_patch __________________________________ def test_patch(): > response = client.patch("/items/foo", json={"name": "Foo"}) tests/test_extra_routes.py:354: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:614: in patch return self.request('PATCH', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_trace __________________________________ def test_trace(): > response = client.request("trace", "/items/foo") tests/test_extra_routes.py:360: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_filter_pydantic_sub_model.py:131: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_filter_sub_model _____________________________ def test_filter_sub_model(): > response = client.get("/model/modelA") tests/test_filter_pydantic_sub_model.py:137: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/model/modelA', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_validator_is_cloned ___________________________ def test_validator_is_cloned(): with pytest.raises(ValidationError) as err: > client.get("/model/modelX") tests/test_filter_pydantic_sub_model.py:148: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/model/modelX', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_python_list_param_as_form ________________________ def test_python_list_param_as_form(): > response = client.post( "/form/python-list", data={"items": ["first", "second", "third"]} ) tests/test_forms_from_non_typing_sequences.py:26: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/form/python-list', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'36'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_python_set_param_as_form _________________________ def test_python_set_param_as_form(): > response = client.post( "/form/python-set", data={"items": ["first", "second", "third"]} ) tests/test_forms_from_non_typing_sequences.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/form/python-set', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'36'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_python_tuple_param_as_form ________________________ def test_python_tuple_param_as_form(): > response = client.post( "/form/python-tuple", data={"items": ["first", "second", "third"]} ) tests/test_forms_from_non_typing_sequences.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/form/python-tuple', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'36'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_get_request_body.py:100: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_get_with_body ______________________________ def test_get_with_body(): body = {"name": "Foo", "description": "Some description", "price": 5.5} > response = client.get("/product", json=body) tests/test_get_request_body.py:107: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/product', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'64'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_value_extracting_by_http _________________________ def test_value_extracting_by_http(): > response = client.get("/http") tests/test_http_connection_injection.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/http', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_value_extracting_by_ws __________________________ def test_value_extracting_by_ws(): > with client.websocket_connect("/ws") as websocket: tests/test_http_connection_injection.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _______________________________ test_sub_router ________________________________ def test_sub_router(): > response = client.get("/items/") tests/test_include_route.py:20: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): client = TestClient(app) > response = client.get("/openapi.json") tests/test_include_router_defaults_overrides.py:346: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_level1_override _____________________________ def test_level1_override(): > response = client.get("/override1?level1=foo") tests/test_include_router_defaults_overrides.py:351: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/override1' query = 'level1=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_level1_default ______________________________ def test_level1_default(): > response = client.get("/default1?level1=foo") tests/test_include_router_defaults_overrides.py:363: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/default1', query = 'level1=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_paths_level3[True-True-True] _______________________ override1 = True, override2 = True, override3 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/override3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_paths_level3[True-True-False] ______________________ override1 = False, override2 = True, override3 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/override3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_paths_level3[True-False-True] ______________________ override1 = True, override2 = False, override3 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/override3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_paths_level3[True-False-False] ______________________ override1 = False, override2 = False, override3 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/override3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_paths_level3[False-True-True] ______________________ override1 = True, override2 = True, override3 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/default3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_paths_level3[False-True-False] ______________________ override1 = False, override2 = True, override3 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/default3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_paths_level3[False-False-True] ______________________ override1 = True, override2 = False, override3 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/default3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_paths_level3[False-False-False] _____________________ override1 = False, override2 = False, override3 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/default3', query = 'level3=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[True-True-True-True-True] __________________ override1 = True, override2 = True, override3 = True, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/level1/level2/level3/level4/override5', query = 'level5=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[True-True-True-True-False] _________________ override1 = False, override2 = True, override3 = True, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level3/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[True-True-True-False-True] _________________ override1 = True, override2 = False, override3 = True, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level3/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-True-True-False-False] _________________ override1 = False, override2 = False, override3 = True, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level3/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[True-True-False-True-True] _________________ override1 = True, override2 = True, override3 = False, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-True-False-True-False] _________________ override1 = False, override2 = True, override3 = False, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-True-False-False-True] _________________ override1 = True, override2 = False, override3 = False, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-True-False-False-False] ________________ override1 = False, override2 = False, override3 = False, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[True-False-True-True-True] _________________ override1 = True, override2 = True, override3 = True, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/level3/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-True-True-False] _________________ override1 = False, override2 = True, override3 = True, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level3/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-True-False-True] _________________ override1 = True, override2 = False, override3 = True, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level3/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-True-False-False] ________________ override1 = False, override2 = False, override3 = True, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level3/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-False-True-True] _________________ override1 = True, override2 = True, override3 = False, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-False-True-False] ________________ override1 = False, override2 = True, override3 = False, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-False-False-True] ________________ override1 = True, override2 = False, override3 = False, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[True-False-False-False-False] ________________ override1 = False, override2 = False, override3 = False, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[False-True-True-True-True] _________________ override1 = True, override2 = True, override3 = True, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/level1/level2/level3/level4/default5', query = 'level5=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-True-True-False] _________________ override1 = False, override2 = True, override3 = True, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level3/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-True-False-True] _________________ override1 = True, override2 = False, override3 = True, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level3/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-True-False-False] ________________ override1 = False, override2 = False, override3 = True, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level3/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-False-True-True] _________________ override1 = True, override2 = True, override3 = False, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-False-True-False] ________________ override1 = False, override2 = True, override3 = False, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-False-False-True] ________________ override1 = True, override2 = False, override3 = False, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[False-True-False-False-False] ________________ override1 = False, override2 = False, override3 = False, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-False-True-True-True] _________________ override1 = True, override2 = True, override3 = True, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/level3/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-False-True-True-False] ________________ override1 = False, override2 = True, override3 = True, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level3/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-False-True-False-True] ________________ override1 = True, override2 = False, override3 = True, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level3/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[False-False-True-False-False] ________________ override1 = False, override2 = False, override3 = True, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level3/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-False-False-True-True] ________________ override1 = True, override2 = True, override3 = False, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[False-False-False-True-False] ________________ override1 = False, override2 = True, override3 = False, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[False-False-False-False-True] ________________ override1 = True, override2 = False, override3 = False, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[False-False-False-False-False] _______________ override1 = False, override2 = False, override3 = False, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/default5', query = 'level5=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_users ________________________________ def test_get_users(): """Check that /users returns expected data""" > response = client.get("/users") tests/test_infer_param_optionality.py:50: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_user _________________________________ def test_get_user(): """Check that /users/{user_id} returns expected data""" > response = client.get("/users/abc123") tests/test_infer_param_optionality.py:57: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/abc123', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_get_items_1 _______________________________ def test_get_items_1(): """Check that /items returns expected data""" > response = client.get("/items") tests/test_infer_param_optionality.py:64: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_get_items_2 _______________________________ def test_get_items_2(): """Check that /items returns expected data with user_id specified""" > response = client.get("/items?user_id=abc123") tests/test_infer_param_optionality.py:74: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items' query = 'user_id=abc123', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_get_item_1 ________________________________ def test_get_item_1(): """Check that /items/{item_id} returns expected data""" > response = client.get("/items/item01") tests/test_infer_param_optionality.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/item01', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_get_item_2 ________________________________ def test_get_item_2(): """Check that /items/{item_id} returns expected data with user_id specified""" > response = client.get("/items/item01?user_id=abc123") tests/test_infer_param_optionality.py:88: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/item01' query = 'user_id=abc123', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_users_items _____________________________ def test_get_users_items(): """Check that /users/{user_id}/items returns expected data""" > response = client.get("/users/abc123/items") tests/test_infer_param_optionality.py:95: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/abc123/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_users_item ______________________________ def test_get_users_item(): """Check that /users/{user_id}/items returns expected data""" > response = client.get("/users/abc123/items/item01") tests/test_infer_param_optionality.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/abc123/items/item01' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_schema_1 _________________________________ def test_schema_1(): """Check that the user_id is a required path parameter under /users""" > response = client.get("/openapi.json") tests/test_infer_param_optionality.py:109: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_schema_2 _________________________________ def test_schema_2(): """Check that the user_id is an optional query parameter under /items""" > response = client.get("/openapi.json") tests/test_infer_param_optionality.py:126: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_dt ____________________________________ def test_dt(): > with client: tests/test_inherited_custom_class.py:63: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_multi_body_errors.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_put_correct_body _____________________________ def test_put_correct_body(): > response = client.post("/items/", json=[{"name": "Foo", "age": 5}]) tests/test_multi_body_errors.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'27'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_jsonable_encoder_requiring_error _____________________ def test_jsonable_encoder_requiring_error(): > response = client.post("/items/", json=[{"name": "Foo", "age": -1.0}]) tests/test_multi_body_errors.py:153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'30'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_put_incorrect_body_multiple _______________________ def test_put_incorrect_body_multiple(): > response = client.post("/items/", json=[{"age": "five"}, {"age": "six"}]) tests/test_multi_body_errors.py:159: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'33'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_multi_query_errors.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_multi_query _______________________________ def test_multi_query(): > response = client.get("/items/?q=5&q=6") tests/test_multi_query_errors.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=5&q=6' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_multi_query_incorrect __________________________ def test_multi_query_incorrect(): > response = client.get("/items/?q=five&q=six") tests/test_multi_query_errors.py:116: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=five&q=six' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_swagger_ui ________________________________ def test_swagger_ui(): > response = client.get("/docs") tests/test_no_swagger_ui_redirect.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_swagger_ui_no_oauth2_redirect ______________________ def test_swagger_ui_no_oauth2_redirect(): > response = client.get("/docs/oauth2-redirect") tests/test_no_swagger_ui_redirect.py:25: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs/oauth2-redirect' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_response _________________________________ def test_response(): > response = client.get("/items/") tests/test_no_swagger_ui_redirect.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_servers _____________________________ def test_openapi_servers(): > response = client.get("/openapi.json") tests/test_openapi_servers.py:53: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_app ___________________________________ def test_app(): > response = client.get("/foo") tests/test_openapi_servers.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/foo', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_default_param_query_none _________________________ def test_default_param_query_none(): > response = client.get("/items/") tests/test_param_class.py:19: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_default_param_query ___________________________ def test_default_param_query(): > response = client.get("/items/?q=foo") tests/test_param_class.py:25: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_reused_param _______________________________ def test_reused_param(): > response = client.get("/openapi.json") tests/test_param_in_path_and_dependency.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_read_users ________________________________ def test_read_users(): > response = client.get("/users/42") tests/test_param_in_path_and_dependency.py:92: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_text_get _________________________________ def test_text_get(): > response = client.get("/text") tests/test_path.py:10: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/text', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_nonexistent _______________________________ def test_nonexistent(): > response = client.get("/nonexistent") tests/test_path.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/nonexistent', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/foobar-200-foobar] ____________________ path = '/path/foobar', expected_status = 200, expected_response = 'foobar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/foobar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/str/foobar-200-foobar] __________________ path = '/path/str/foobar', expected_status = 200, expected_response = 'foobar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/str/foobar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_get_path[/path/str/42-200-42] ______________________ path = '/path/str/42', expected_status = 200, expected_response = '42' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/str/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/str/True-200-True] ____________________ path = '/path/str/True', expected_status = 200, expected_response = 'True' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/str/True', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get_path[/path/int/foobar-422-expected_response4] ____________ path = '/path/int/foobar', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/int/foobar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/path/int/True-422-expected_response5] _____________ path = '/path/int/True', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/int/True', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_get_path[/path/int/42-200-42] ______________________ path = '/path/int/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/int/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/path/int/42.5-422-expected_response7] _____________ path = '/path/int/42.5', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/int/42.5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/float/foobar-422-expected_response8] ___________ path = '/path/float/foobar', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid float', 'type': 'type_error.float'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/float/foobar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get_path[/path/float/True-422-expected_response9] ____________ path = '/path/float/True', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid float', 'type': 'type_error.float'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/float/True', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_get_path[/path/float/42-200-42] _____________________ path = '/path/float/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/float/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/float/42.5-200-42.5] ___________________ path = '/path/float/42.5', expected_status = 200, expected_response = 42.5 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/float/42.5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/bool/foobar-422-expected_response12] ___________ path = '/path/bool/foobar', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value could not be parsed to a boolean', 'type': 'type_error.bool'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/foobar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/bool/True-200-True] ____________________ path = '/path/bool/True', expected_status = 200, expected_response = True @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/True', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/path/bool/42-422-expected_response14] _____________ path = '/path/bool/42', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value could not be parsed to a boolean', 'type': 'type_error.bool'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get_path[/path/bool/42.5-422-expected_response15] ____________ path = '/path/bool/42.5', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value could not be parsed to a boolean', 'type': 'type_error.bool'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/42.5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_get_path[/path/bool/1-200-True] _____________________ path = '/path/bool/1', expected_status = 200, expected_response = True @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/1', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/bool/0-200-False] _____________________ path = '/path/bool/0', expected_status = 200, expected_response = False @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/0', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/bool/true-200-True] ____________________ path = '/path/bool/true', expected_status = 200, expected_response = True @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/true', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/bool/False-200-False] ___________________ path = '/path/bool/False', expected_status = 200, expected_response = False @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/False', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/bool/false-200-False] ___________________ path = '/path/bool/false', expected_status = 200, expected_response = False @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/false', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/param/foo-200-foo] ____________________ path = '/path/param/foo', expected_status = 200, expected_response = 'foo' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/path/param-required/foo-200-foo] ________________ path = '/path/param-required/foo', expected_status = 200 expected_response = 'foo' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-required/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/path/param-minlength/foo-200-foo] _______________ path = '/path/param-minlength/foo', expected_status = 200 expected_response = 'foo' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-minlength/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/path/param-minlength/fo-422-expected_response24] ________ path = '/path/param-minlength/fo', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value has at least 3 characters', 'type': 'value_error.any_str.min_length'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-minlength/fo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/path/param-maxlength/foo-200-foo] _______________ path = '/path/param-maxlength/foo', expected_status = 200 expected_response = 'foo' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-maxlength/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_get_path[/path/param-maxlength/foobar-422-expected_response26] ______ path = '/path/param-maxlength/foobar', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value has at most 3 characters', 'type': 'value_error.any_str.max_length'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-maxlength/foobar' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/path/param-min_maxlength/foo-200-foo] _____________ path = '/path/param-min_maxlength/foo', expected_status = 200 expected_response = 'foo' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-min_maxlength/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_get_path[/path/param-min_maxlength/foobar-422-expected_response28] ____ path = '/path/param-min_maxlength/foobar', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value has at most 3 characters', 'type': 'value_error.any_str.max_length'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/path/param-min_maxlength/foobar', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______ test_get_path[/path/param-min_maxlength/f-422-expected_response29] ______ path = '/path/param-min_maxlength/f', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 2}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value has at least 2 characters', 'type': 'value_error.any_str.min_length'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-min_maxlength/f' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-gt/42-200-42] ____________________ path = '/path/param-gt/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-gt/2-422-expected_response31] ____________ path = '/path/param-gt/2', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than 3', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-gt0/0.05-200-0.05] _________________ path = '/path/param-gt0/0.05', expected_status = 200, expected_response = 0.05 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt0/0.05' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-gt0/0-422-expected_response33] ___________ path = '/path/param-gt0/0', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 0}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than 0', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt0/0', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-ge/42-200-42] ____________________ path = '/path/param-ge/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/param-ge/3-200-3] _____________________ path = '/path/param-ge/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge/3', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-ge/2-422-expected_response36] ____________ path = '/path/param-ge/2', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than or equal to 3', 'type': 'value_error.number.not_ge'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-lt/42-422-expected_response37] ___________ path = '/path/param-lt/42', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than 3', 'type': 'value_error.number.not_lt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/param-lt/2-200-2] _____________________ path = '/path/param-lt/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-lt0/-1-200--1] ___________________ path = '/path/param-lt0/-1', expected_status = 200, expected_response = -1 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt0/-1', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-lt0/0-422-expected_response40] ___________ path = '/path/param-lt0/0', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 0}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than 0', 'type': 'value_error.number.not_lt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt0/0', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-le/42-422-expected_response41] ___________ path = '/path/param-le/42', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than or equal to 3', 'type': 'value_error.number.not_le'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/param-le/3-200-3] _____________________ path = '/path/param-le/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le/3', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/param-le/2-200-2] _____________________ path = '/path/param-le/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-lt-gt/2-200-2] ___________________ path = '/path/param-lt-gt/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/path/param-lt-gt/4-422-expected_response45] __________ path = '/path/param-lt-gt/4', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than 3', 'type': 'value_error.number.not_lt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt/4', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/path/param-lt-gt/0-422-expected_response46] __________ path = '/path/param-lt-gt/0', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 1}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than 1', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt/0', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-le-ge/2-200-2] ___________________ path = '/path/param-le-ge/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-le-ge/1-200-1] ___________________ path = '/path/param-le-ge/1', expected_status = 200, expected_response = 1 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge/1', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-le-ge/3-200-3] ___________________ path = '/path/param-le-ge/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge/3', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/path/param-le-ge/4-422-expected_response50] __________ path = '/path/param-le-ge/4', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than or equal to 3', 'type': 'value_error.number.not_le'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge/4', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/param-lt-int/2-200-2] ___________________ path = '/path/param-lt-int/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/path/param-lt-int/42-422-expected_response52] _________ path = '/path/param-lt-int/42', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than 3', 'type': 'value_error.number.not_lt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-int/42' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-lt-int/2.7-422-expected_response53] _________ path = '/path/param-lt-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-gt-int/42-200-42] __________________ path = '/path/param-gt-int/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt-int/42' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/path/param-gt-int/2-422-expected_response55] __________ path = '/path/param-gt-int/2', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than 3', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-gt-int/2.7-422-expected_response56] _________ path = '/path/param-gt-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/path/param-le-int/42-422-expected_response57] _________ path = '/path/param-le-int/42', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than or equal to 3', 'type': 'value_error.number.not_le'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-int/42' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/param-le-int/3-200-3] ___________________ path = '/path/param-le-int/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-int/3' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/param-le-int/2-200-2] ___________________ path = '/path/param-le-int/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-le-int/2.7-422-expected_response60] _________ path = '/path/param-le-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-ge-int/42-200-42] __________________ path = '/path/param-ge-int/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge-int/42' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/param-ge-int/3-200-3] ___________________ path = '/path/param-ge-int/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge-int/3' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/path/param-ge-int/2-422-expected_response63] __________ path = '/path/param-ge-int/2', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than or equal to 3', 'type': 'value_error.number.not_ge'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-ge-int/2.7-422-expected_response64] _________ path = '/path/param-ge-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-lt-gt-int/2-200-2] _________________ path = '/path/param-lt-gt-int/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-lt-gt-int/4-422-expected_response66] ________ path = '/path/param-lt-gt-int/4', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than 3', 'type': 'value_error.number.not_lt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt-int/4' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-lt-gt-int/0-422-expected_response67] ________ path = '/path/param-lt-gt-int/0', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 1}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than 1', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt-int/0' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/path/param-lt-gt-int/2.7-422-expected_response68] _______ path = '/path/param-lt-gt-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-le-ge-int/2-200-2] _________________ path = '/path/param-le-ge-int/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-le-ge-int/1-200-1] _________________ path = '/path/param-le-ge-int/1', expected_status = 200, expected_response = 1 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge-int/1' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-le-ge-int/3-200-3] _________________ path = '/path/param-le-ge-int/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge-int/3' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-le-ge-int/4-422-expected_response72] ________ path = '/path/param-le-ge-int/4', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than or equal to 3', 'type': 'value_error.number.not_le'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge-int/4' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/path/param-le-ge-int/2.7-422-expected_response73] _______ path = '/path/param-le-ge-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_put_no_body.py:83: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_put_no_body _______________________________ def test_put_no_body(): > response = client.put("/items/foo") tests/test_put_no_body.py:89: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_put_no_body_with_body __________________________ def test_put_no_body_with_body(): > response = client.put("/items/foo", json={"name": "Foo"}) tests/test_put_no_body.py:95: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/query-422-expected_response0] _________________ path = '/query', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/query?query=baz-200-foo bar baz] ________________ path = '/query?query=baz', expected_status = 200 expected_response = 'foo bar baz' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query', query = 'query=baz' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/query?not_declared=baz-422-expected_response2] _________ path = '/query?not_declared=baz', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query' query = 'not_declared=baz', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/query/optional-200-foo bar] __________________ path = '/query/optional', expected_status = 200, expected_response = 'foo bar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/optional', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/query/optional?query=baz-200-foo bar baz] ___________ path = '/query/optional?query=baz', expected_status = 200 expected_response = 'foo bar baz' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/optional' query = 'query=baz', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/query/optional?not_declared=baz-200-foo bar] __________ path = '/query/optional?not_declared=baz', expected_status = 200 expected_response = 'foo bar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/optional' query = 'not_declared=baz', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/query/int-422-expected_response6] _______________ path = '/query/int', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_get_path[/query/int?query=42-200-foo bar 42] _______________ path = '/query/int?query=42', expected_status = 200 expected_response = 'foo bar 42' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int', query = 'query=42' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/query/int?query=42.5-422-expected_response8] __________ path = '/query/int?query=42.5', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int' query = 'query=42.5', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/query/int?query=baz-422-expected_response9] __________ path = '/query/int?query=baz', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int', query = 'query=baz' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______ test_get_path[/query/int?not_declared=baz-422-expected_response10] ______ path = '/query/int?not_declared=baz', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int' query = 'not_declared=baz', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_get_path[/query/int/optional-200-foo bar] ________________ path = '/query/int/optional', expected_status = 200 expected_response = 'foo bar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/optional', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/query/int/optional?query=50-200-foo bar 50] __________ path = '/query/int/optional?query=50', expected_status = 200 expected_response = 'foo bar 50' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/optional' query = 'query=50', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_get_path[/query/int/optional?query=foo-422-expected_response13] _____ path = '/query/int/optional?query=foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/optional' query = 'query=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/query/int/default-200-foo bar 10] _______________ path = '/query/int/default', expected_status = 200 expected_response = 'foo bar 10' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/default', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/query/int/default?query=50-200-foo bar 50] ___________ path = '/query/int/default?query=50', expected_status = 200 expected_response = 'foo bar 50' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/default' query = 'query=50', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_get_path[/query/int/default?query=foo-422-expected_response16] ______ path = '/query/int/default?query=foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/default' query = 'query=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/query/param-200-foo bar] ____________________ path = '/query/param', expected_status = 200, expected_response = 'foo bar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/query/param?query=50-200-foo bar 50] ______________ path = '/query/param?query=50', expected_status = 200 expected_response = 'foo bar 50' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param' query = 'query=50', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/query/param-required-422-expected_response19] _________ path = '/query/param-required', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param-required' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/query/param-required?query=50-200-foo bar 50] _________ path = '/query/param-required?query=50', expected_status = 200 expected_response = 'foo bar 50' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param-required' query = 'query=50', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/query/param-required/int-422-expected_response21] _______ path = '/query/param-required/int', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param-required/int' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/query/param-required/int?query=50-200-foo bar 50] _______ path = '/query/param-required/int?query=50', expected_status = 200 expected_response = 'foo bar 50' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param-required/int' query = 'query=50', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __ test_get_path[/query/param-required/int?query=foo-422-expected_response23] __ path = '/query/param-required/int?query=foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param-required/int' query = 'query=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_cookie_is_set_once ____________________________ def test_cookie_is_set_once(): > direct_response = client.get("/directCookie") tests/test_repeated_cookie_headers.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/directCookie', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_schema __________________________________ def test_schema(): > response = client.get("/openapi.json") tests/test_repeated_dependency_schema.py:90: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_response _________________________________ def test_response(): > response = client.get("/", headers={"someheader": "hello"}) tests/test_repeated_dependency_schema.py:100: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'someheader', b'hello')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_request_body_parameters_media_type.py:58: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_dependency_set_status_code ________________________ def test_dependency_set_status_code(): > response = client.get("/") tests/test_response_change_status_code.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_response_class_no_mediatype.py:112: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_response_code_no_body.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_response_model_sub_types.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operations _____________________________ def test_path_operations(): > response = client.get("/valid1") tests/test_response_model_sub_types.py:153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/valid1', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_router_events ______________________________ def test_router_events(): assert state.app_startup is False assert state.router_startup is False assert state.sub_router_startup is False assert state.app_shutdown is False assert state.router_shutdown is False assert state.sub_router_shutdown is False > with TestClient(app) as client: tests/test_router_events.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/seg/users/foo") tests/test_router_prefix_with_template.py:21: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/seg/users/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_cookie.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me", cookies={"key": "secret"}) tests/test_security_api_key_cookie.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'cookie', b'key=secret')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_cookie.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_cookie_optional.py:61: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me", cookies={"key": "secret"}) tests/test_security_api_key_cookie_optional.py:67: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'cookie', b'key=secret')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_cookie_optional.py:73: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_header.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me", headers={"key": "secret"}) tests/test_security_api_key_header.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'key', b'secret')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_header.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_header_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me", headers={"key": "secret"}) tests/test_security_api_key_header_optional.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'key', b'secret')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_header_optional.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_query.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me?key=secret") tests/test_security_api_key_query.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = 'key=secret' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_query.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_query_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me?key=secret") tests/test_security_api_key_query_optional.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = 'key=secret' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_query_optional.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_base.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_security_http_base ____________________________ def test_security_http_base(): > response = client.get("/users/me", headers={"Authorization": "Other foobar"}) tests/test_security_http_base.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_security_http_base_no_credentials ____________________ def test_security_http_base_no_credentials(): > response = client.get("/users/me") tests/test_security_http_base.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_base_optional.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_security_http_base ____________________________ def test_security_http_base(): > response = client.get("/users/me", headers={"Authorization": "Other foobar"}) tests/test_security_http_base_optional.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_security_http_base_no_credentials ____________________ def test_security_http_base_no_credentials(): > response = client.get("/users/me") tests/test_security_http_base_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_basic_optional.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_security_http_basic ___________________________ def test_security_http_basic(): auth = HTTPBasicAuth(username="john", password="secret") > response = client.get("/users/me", auth=auth) tests/test_security_http_basic_optional.py:55: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9objpzZWNyZXQ=')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_basic_no_credentials ____________________ def test_security_http_basic_no_credentials(): > response = client.get("/users/me") tests/test_security_http_basic_optional.py:61: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_security_http_basic_invalid_credentials _________________ def test_security_http_basic_invalid_credentials(): > response = client.get( "/users/me", headers={"Authorization": "Basic notabase64token"} ) tests/test_security_http_basic_optional.py:67: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic notabase64token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_http_basic_non_basic_credentials ________________ def test_security_http_basic_non_basic_credentials(): payload = b64encode(b"johnsecret").decode("ascii") auth_header = f"Basic {payload}" > response = client.get("/users/me", headers={"Authorization": auth_header}) tests/test_security_http_basic_optional.py:78: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9obnNlY3JldA==')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_basic_realm.py:45: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_security_http_basic ___________________________ def test_security_http_basic(): auth = HTTPBasicAuth(username="john", password="secret") > response = client.get("/users/me", auth=auth) tests/test_security_http_basic_realm.py:52: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9objpzZWNyZXQ=')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_basic_no_credentials ____________________ def test_security_http_basic_no_credentials(): > response = client.get("/users/me") tests/test_security_http_basic_realm.py:58: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_security_http_basic_invalid_credentials _________________ def test_security_http_basic_invalid_credentials(): > response = client.get( "/users/me", headers={"Authorization": "Basic notabase64token"} ) tests/test_security_http_basic_realm.py:65: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic notabase64token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_http_basic_non_basic_credentials ________________ def test_security_http_basic_non_basic_credentials(): payload = b64encode(b"johnsecret").decode("ascii") auth_header = f"Basic {payload}" > response = client.get("/users/me", headers={"Authorization": auth_header}) tests/test_security_http_basic_realm.py:76: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9obnNlY3JldA==')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_bearer.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_security_http_bearer ___________________________ def test_security_http_bearer(): > response = client.get("/users/me", headers={"Authorization": "Bearer foobar"}) tests/test_security_http_bearer.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_bearer_no_credentials ___________________ def test_security_http_bearer_no_credentials(): > response = client.get("/users/me") tests/test_security_http_bearer.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_security_http_bearer_incorrect_scheme_credentials ____________ def test_security_http_bearer_incorrect_scheme_credentials(): > response = client.get("/users/me", headers={"Authorization": "Basic notreally"}) tests/test_security_http_bearer.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic notreally')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_bearer_optional.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_security_http_bearer ___________________________ def test_security_http_bearer(): > response = client.get("/users/me", headers={"Authorization": "Bearer foobar"}) tests/test_security_http_bearer_optional.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_bearer_no_credentials ___________________ def test_security_http_bearer_no_credentials(): > response = client.get("/users/me") tests/test_security_http_bearer_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_security_http_bearer_incorrect_scheme_credentials ____________ def test_security_http_bearer_incorrect_scheme_credentials(): > response = client.get("/users/me", headers={"Authorization": "Basic notreally"}) tests/test_security_http_bearer_optional.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic notreally')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_digest.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_security_http_digest ___________________________ def test_security_http_digest(): > response = client.get("/users/me", headers={"Authorization": "Digest foobar"}) tests/test_security_http_digest.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Digest foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_digest_no_credentials ___________________ def test_security_http_digest_no_credentials(): > response = client.get("/users/me") tests/test_security_http_digest.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_security_http_digest_incorrect_scheme_credentials ____________ def test_security_http_digest_incorrect_scheme_credentials(): > response = client.get( "/users/me", headers={"Authorization": "Other invalidauthorization"} ) tests/test_security_http_digest.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other invalidauthorization')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_digest_optional.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_security_http_digest ___________________________ def test_security_http_digest(): > response = client.get("/users/me", headers={"Authorization": "Digest foobar"}) tests/test_security_http_digest_optional.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Digest foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_digest_no_credentials ___________________ def test_security_http_digest_no_credentials(): > response = client.get("/users/me") tests/test_security_http_digest_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_security_http_digest_incorrect_scheme_credentials ____________ def test_security_http_digest_incorrect_scheme_credentials(): > response = client.get( "/users/me", headers={"Authorization": "Other invalidauthorization"} ) tests/test_security_http_digest_optional.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other invalidauthorization')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_oauth2.py:157: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_security_oauth2 _____________________________ def test_security_oauth2(): > response = client.get("/users/me", headers={"Authorization": "Bearer footokenbar"}) tests/test_security_oauth2.py:163: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_security_oauth2_password_other_header __________________ def test_security_oauth2_password_other_header(): > response = client.get("/users/me", headers={"Authorization": "Other footokenbar"}) tests/test_security_oauth2.py:169: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_oauth2_password_bearer_no_header ________________ def test_security_oauth2_password_bearer_no_header(): > response = client.get("/users/me") tests/test_security_oauth2.py:175: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_strict_login[None-422-expected_response0] ________________ data = None, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'grant_type'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', ...'type': 'value_error.missing'}, {'loc': ['body', 'password'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data1-422-expected_response1] ________________ data = {'password': 'secret', 'username': 'johndoe'}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'grant_type'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'32'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data2-422-expected_response2] ________________ data = {'grant_type': 'incorrect', 'password': 'secret', 'username': 'johndoe'} expected_status = 422 expected_response = {'detail': [{'ctx': {'pattern': 'password'}, 'loc': ['body', 'grant_type'], 'msg': 'string does not match regex "password"', 'type': 'value_error.str.regex'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'53'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data3-200-expected_response3] ________________ data = {'grant_type': 'password', 'password': 'secret', 'username': 'johndoe'} expected_status = 200 expected_response = {'client_id': None, 'client_secret': None, 'grant_type': 'password', 'password': 'secret', ...} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'52'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_oauth2_authorization_code_bearer.py:57: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_no_token _________________________________ def test_no_token(): > response = client.get("/items") tests/test_security_oauth2_authorization_code_bearer.py:63: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_incorrect_token _____________________________ def test_incorrect_token(): > response = client.get("/items", headers={"Authorization": "Non-existent testtoken"}) tests/test_security_oauth2_authorization_code_bearer.py:69: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Non-existent testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_token __________________________________ def test_token(): > response = client.get("/items", headers={"Authorization": "Bearer testtoken"}) tests/test_security_oauth2_authorization_code_bearer.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_oauth2_optional.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_security_oauth2 _____________________________ def test_security_oauth2(): > response = client.get("/users/me", headers={"Authorization": "Bearer footokenbar"}) tests/test_security_oauth2_optional.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_security_oauth2_password_other_header __________________ def test_security_oauth2_password_other_header(): > response = client.get("/users/me", headers={"Authorization": "Other footokenbar"}) tests/test_security_oauth2_optional.py:173: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_oauth2_password_bearer_no_header ________________ def test_security_oauth2_password_bearer_no_header(): > response = client.get("/users/me") tests/test_security_oauth2_optional.py:179: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_strict_login[None-422-expected_response0] ________________ data = None, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'grant_type'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', ...'type': 'value_error.missing'}, {'loc': ['body', 'password'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2_optional.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data1-422-expected_response1] ________________ data = {'password': 'secret', 'username': 'johndoe'}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'grant_type'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2_optional.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'32'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data2-422-expected_response2] ________________ data = {'grant_type': 'incorrect', 'password': 'secret', 'username': 'johndoe'} expected_status = 422 expected_response = {'detail': [{'ctx': {'pattern': 'password'}, 'loc': ['body', 'grant_type'], 'msg': 'string does not match regex "password"', 'type': 'value_error.str.regex'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2_optional.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'53'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data3-200-expected_response3] ________________ data = {'grant_type': 'password', 'password': 'secret', 'username': 'johndoe'} expected_status = 200 expected_response = {'client_id': None, 'client_secret': None, 'grant_type': 'password', 'password': 'secret', ...} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2_optional.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'52'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_oauth2_password_bearer_optional.py:51: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_no_token _________________________________ def test_no_token(): > response = client.get("/items") tests/test_security_oauth2_password_bearer_optional.py:57: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_token __________________________________ def test_token(): > response = client.get("/items", headers={"Authorization": "Bearer testtoken"}) tests/test_security_oauth2_password_bearer_optional.py:63: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_incorrect_token _____________________________ def test_incorrect_token(): > response = client.get("/items", headers={"Authorization": "Notexistent testtoken"}) tests/test_security_oauth2_password_bearer_optional.py:69: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Notexistent testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_openid_connect.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_security_oauth2 _____________________________ def test_security_oauth2(): > response = client.get("/users/me", headers={"Authorization": "Bearer footokenbar"}) tests/test_security_openid_connect.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_security_oauth2_password_other_header __________________ def test_security_oauth2_password_other_header(): > response = client.get("/users/me", headers={"Authorization": "Other footokenbar"}) tests/test_security_openid_connect.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_oauth2_password_bearer_no_header ________________ def test_security_oauth2_password_bearer_no_header(): > response = client.get("/users/me") tests/test_security_openid_connect.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_openid_connect_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_security_oauth2 _____________________________ def test_security_oauth2(): > response = client.get("/users/me", headers={"Authorization": "Bearer footokenbar"}) tests/test_security_openid_connect_optional.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_security_oauth2_password_other_header __________________ def test_security_oauth2_password_other_header(): > response = client.get("/users/me", headers={"Authorization": "Other footokenbar"}) tests/test_security_openid_connect_optional.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_oauth2_password_bearer_no_header ________________ def test_security_oauth2_password_bearer_no_header(): > response = client.get("/users/me") tests/test_security_openid_connect_optional.py:78: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_valid __________________________________ def test_valid(): > response = client.get("/items/valid") tests/test_serialize_response.py:39: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/valid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_coerce __________________________________ def test_coerce(): > response = client.get("/items/coerce") tests/test_serialize_response.py:45: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/coerce', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_validlist ________________________________ def test_validlist(): > response = client.get("/items/validlist") tests/test_serialize_response.py:51: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validlist', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_valid __________________________________ def test_valid(): > response = client.get("/items/valid") tests/test_serialize_response_dataclass.py:40: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/valid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_coerce __________________________________ def test_coerce(): > response = client.get("/items/coerce") tests/test_serialize_response_dataclass.py:46: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/coerce', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_validlist ________________________________ def test_validlist(): > response = client.get("/items/validlist") tests/test_serialize_response_dataclass.py:52: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validlist', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_valid __________________________________ def test_valid(): > response = client.get("/items/valid") tests/test_serialize_response_model.py:90: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/valid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_coerce __________________________________ def test_coerce(): > response = client.get("/items/coerce") tests/test_serialize_response_model.py:96: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/coerce', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_validlist ________________________________ def test_validlist(): > response = client.get("/items/validlist") tests/test_serialize_response_model.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validlist', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_validdict ________________________________ def test_validdict(): > response = client.get("/items/validdict") tests/test_serialize_response_model.py:116: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validdict', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_valid_exclude_unset ___________________________ def test_valid_exclude_unset(): > response = client.get("/items/valid-exclude-unset") tests/test_serialize_response_model.py:126: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/valid-exclude-unset' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_coerce_exclude_unset ___________________________ def test_coerce_exclude_unset(): > response = client.get("/items/coerce-exclude-unset") tests/test_serialize_response_model.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/coerce-exclude-unset' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_validlist_exclude_unset _________________________ def test_validlist_exclude_unset(): > response = client.get("/items/validlist-exclude-unset") tests/test_serialize_response_model.py:138: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validlist-exclude-unset' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_validdict_exclude_unset _________________________ def test_validdict_exclude_unset(): > response = client.get("/items/validdict-exclude-unset") tests/test_serialize_response_model.py:148: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validdict-exclude-unset' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_return_defaults _____________________________ def test_return_defaults(): > response = client.get("/") tests/test_skip_defaults.py:74: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_return_exclude_unset ___________________________ def test_return_exclude_unset(): > response = client.get("/exclude_unset") tests/test_skip_defaults.py:79: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/exclude_unset', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_return_exclude_defaults _________________________ def test_return_exclude_defaults(): > response = client.get("/exclude_defaults") tests/test_skip_defaults.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/exclude_defaults', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_return_exclude_none ___________________________ def test_return_exclude_none(): > response = client.get("/exclude_none") tests/test_skip_defaults.py:89: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/exclude_none', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_return_exclude_unset_none ________________________ def test_return_exclude_unset_none(): > response = client.get("/exclude_unset_none") tests/test_skip_defaults.py:94: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/exclude_unset_none', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_starlette_exception.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_item _________________________________ def test_get_item(): > response = client.get("/items/foo") tests/test_starlette_exception.py:134: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_get_item_not_found ____________________________ def test_get_item_not_found(): > response = client.get("/items/bar") tests/test_starlette_exception.py:140: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_get_starlette_item ____________________________ def test_get_starlette_item(): > response = client.get("/starlette-items/foo") tests/test_starlette_exception.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/starlette-items/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_get_starlette_item_not_found _______________________ def test_get_starlette_item_not_found(): > response = client.get("/starlette-items/bar") tests/test_starlette_exception.py:153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/starlette-items/bar' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_route_converters_int ___________________________ def test_route_converters_int(): # Test integer conversion > response = client.get("/int/5") tests/test_starlette_urlconvertors.py:27: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/int/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_route_converters_float __________________________ def test_route_converters_float(): # Test float conversion > response = client.get("/float/25.5") tests/test_starlette_urlconvertors.py:35: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/float/25.5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_route_converters_path __________________________ def test_route_converters_path(): # Test path conversion > response = client.get("/path/some/example") tests/test_starlette_urlconvertors.py:43: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/some/example', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > with client: tests/test_sub_callbacks.py:271: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.post( "/invoices/", json={"id": "fooinvoice", "customer": "John", "total": 5.3} ) tests/test_sub_callbacks.py:278: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/invoices/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'54'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_swagger_ui ________________________________ def test_swagger_ui(): > response = client.get("/docs") tests/test_swagger_ui_init_oauth.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_response _________________________________ def test_response(): > response = client.get("/items/") tests/test_swagger_ui_init_oauth.py:27: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_item_openapi_schema ___________________________ def test_item_openapi_schema(): > response = client.get("/openapi.json") tests/test_union_body.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_other_item _____________________________ def test_post_other_item(): > response = client.post("/items/", json={"price": 100}) tests/test_union_body.py:116: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'14'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_post_item ________________________________ def test_post_item(): > response = client.post("/items/", json={"name": "Foo"}) tests/test_union_body.py:122: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_inherited_item_openapi_schema ______________________ @skip_py36 def test_inherited_item_openapi_schema(): > response = client.get("/openapi.json") tests/test_union_inherited_body.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_post_extended_item ____________________________ @skip_py36 def test_post_extended_item(): > response = client.post("/items/", json={"name": "Foo", "age": 5}) tests/test_union_inherited_body.py:130: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'25'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_post_item ________________________________ @skip_py36 def test_post_item(): > response = client.post("/items/", json={"name": "Foo"}) tests/test_union_inherited_body.py:137: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_invalid _________________________________ def test_invalid(): with pytest.raises(ValidationError): > client.get("/items/invalid") tests/test_validate_response.py:41: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/invalid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_double_invalid ______________________________ def test_double_invalid(): with pytest.raises(ValidationError): > client.get("/items/innerinvalid") tests/test_validate_response.py:46: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/innerinvalid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_invalid_list _______________________________ def test_invalid_list(): with pytest.raises(ValidationError): > client.get("/items/invalidlist") tests/test_validate_response.py:51: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/invalidlist', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_invalid _________________________________ def test_invalid(): with pytest.raises(ValidationError): > client.get("/items/invalid") tests/test_validate_response_dataclass.py:43: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/invalid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_double_invalid ______________________________ def test_double_invalid(): with pytest.raises(ValidationError): > client.get("/items/innerinvalid") tests/test_validate_response_dataclass.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/innerinvalid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_invalid_list _______________________________ def test_invalid_list(): with pytest.raises(ValidationError): > client.get("/items/invalidlist") tests/test_validate_response_dataclass.py:53: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/invalidlist', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_recursive ________________________________ def test_recursive(): > response = client.get("/items/recursive") tests/test_validate_response_recursive.py:58: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/recursive', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_app ___________________________________ def test_app(): client = TestClient(app) > with client.websocket_connect("/") as websocket: tests/test_ws_router.py:56: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _________________________________ test_router __________________________________ def test_router(): client = TestClient(app) > with client.websocket_connect("/router") as websocket: tests/test_ws_router.py:63: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError ______________________________ test_prefix_router ______________________________ def test_prefix_router(): client = TestClient(app) > with client.websocket_connect("/prefix/") as websocket: tests/test_ws_router.py:70: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _________________________________ test_router2 _________________________________ def test_router2(): client = TestClient(app) > with client.websocket_connect("/router2") as websocket: tests/test_ws_router.py:77: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError ____________________________ test_router_ws_depends ____________________________ def test_router_ws_depends(): client = TestClient(app) > with client.websocket_connect("/router-ws-depends/") as websocket: tests/test_ws_router.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _____________________ test_router_ws_depends_with_override _____________________ def test_router_ws_depends_with_override(): client = TestClient(app) app.dependency_overrides[ws_dependency] = lambda: "Override" > with client.websocket_connect("/router-ws-depends/") as websocket: tests/test_ws_router.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_modules_same_name_body/test_main.py:127: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_post_a __________________________________ def test_post_a(): data = {"a": 2, "b": "foo"} > response = client.post("/a/compute", json=data) tests/test_modules_same_name_body/test_main.py:134: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a/compute', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'20'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_a_invalid ______________________________ def test_post_a_invalid(): data = {"a": "bar", "b": "foo"} > response = client.post("/a/compute", json=data) tests/test_modules_same_name_body/test_main.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a/compute', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'24'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_post_b __________________________________ def test_post_b(): data = {"a": 2, "b": "foo"} > response = client.post("/b/compute/", json=data) tests/test_modules_same_name_body/test_main.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/b/compute/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'20'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_b_invalid ______________________________ def test_post_b_invalid(): data = {"a": "bar", "b": "foo"} > response = client.post("/b/compute/", json=data) tests/test_modules_same_name_body/test_main.py:154: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/b/compute/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'24'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_additional_responses/test_tutorial001.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/items/foo") tests/test_tutorial/test_additional_responses/test_tutorial001.py:108: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_path_operation_not_found _________________________ def test_path_operation_not_found(): > response = client.get("/items/bar") tests/test_tutorial/test_additional_responses/test_tutorial001.py:114: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_additional_responses/test_tutorial002.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/items/foo") tests/test_tutorial/test_additional_responses/test_tutorial002.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_path_operation_img ____________________________ def test_path_operation_img(): shutil.copy("./docs/en/docs/img/favicon.png", "./image.png") > response = client.get("/items/foo?img=1") tests/test_tutorial/test_additional_responses/test_tutorial002.py:111: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = 'img=1' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_additional_responses/test_tutorial003.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/items/foo") tests/test_tutorial/test_additional_responses/test_tutorial003.py:109: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_path_operation_not_found _________________________ def test_path_operation_not_found(): > response = client.get("/items/bar") tests/test_tutorial/test_additional_responses/test_tutorial003.py:115: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_additional_responses/test_tutorial004.py:101: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/items/foo") tests/test_tutorial/test_additional_responses/test_tutorial004.py:107: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_path_operation_img ____________________________ def test_path_operation_img(): shutil.copy("./docs/en/docs/img/favicon.png", "./image.png") > response = client.get("/items/foo?img=1") tests/test_tutorial/test_additional_responses/test_tutorial004.py:114: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = 'img=1' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_update __________________________________ def test_update(): > response = client.put("/items/foo", json={"name": "Wrestlers"}) tests/test_tutorial/test_additional_status_codes/test_tutorial001.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'21'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_create __________________________________ def test_create(): > response = client.put("/items/red", json={"name": "Chillies"}) tests/test_tutorial/test_additional_status_codes/test_tutorial001.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/red', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'20'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_middleware ________________________________ def test_middleware(): client = TestClient(app, base_url="https://testserver") > response = client.get("/") tests/test_tutorial/test_advanced_middleware/test_tutorial001.py:8: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'https', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 443, host = 'testserver', port = 443 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_middleware ________________________________ def test_middleware(): client = TestClient(app, base_url="http://example.com") > response = client.get("/") tests/test_tutorial/test_advanced_middleware/test_tutorial002.py:8: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'example.com', path = '/', query = '', fragment = '' default_port = 80, host = 'example.com', port = 80 headers = [(b'host', b'example.com'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_middleware ________________________________ def test_middleware(): > response = client.get("/large", headers={"accept-encoding": "gzip"}) tests/test_tutorial/test_advanced_middleware/test_tutorial003.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/large', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > with TestClient(app) as client: tests/test_tutorial/test_async_sql_databases/test_tutorial001.py:114: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________________ test_create_read _______________________________ def test_create_read(): > with TestClient(app) as client: tests/test_tutorial/test_async_sql_databases/test_tutorial001.py:121: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError __________________________________ test_root ___________________________________ @pytest.mark.asyncio async def test_root(): async with AsyncClient(app=app, base_url="http://test") as ac: > response = await ac.get("/") docs_src/async_tests/test_main.py:10: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/httpx/_client.py:1548: in get return await self.request( /usr/lib/python3/dist-packages/httpx/_client.py:1371: in request response = await self.send( /usr/lib/python3/dist-packages/httpx/_client.py:1406: in send response = await self._send_handling_auth( /usr/lib/python3/dist-packages/httpx/_client.py:1444: in _send_handling_auth response = await self._send_handling_redirects( /usr/lib/python3/dist-packages/httpx/_client.py:1476: in _send_handling_redirects response = await self._send_single_request(request, timeout) /usr/lib/python3/dist-packages/httpx/_client.py:1502: in _send_single_request (status_code, headers, stream, ext,) = await transport.arequest( _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , method = b'GET' url = (b'http', b'test', None, b'/') headers = [(b'Host', b'test'), (b'Accept', b'*/*'), (b'Accept-Encoding', b'gzip, deflate'), (b'Connection', b'keep-alive'), (b'User-Agent', b'python-httpx/0.16.1')] stream = ext = {'timeout': {'connect': 5.0, 'pool': 5.0, 'read': 5.0, 'write': 5.0}} async def arequest( self, method: bytes, url: Tuple[bytes, bytes, Optional[int], bytes], headers: List[Tuple[bytes, bytes]] = None, stream: httpcore.AsyncByteStream = None, ext: dict = None, ) -> Tuple[int, List[Tuple[bytes, bytes]], httpcore.AsyncByteStream, dict]: headers = [] if headers is None else headers stream = httpcore.PlainByteStream(content=b"") if stream is None else stream # ASGI scope. scheme, host, port, full_path = url path, _, query = full_path.partition(b"?") scope = { "type": "http", "asgi": {"version": "3.0"}, "http_version": "1.1", "method": method.decode(), "headers": [(k.lower(), v) for (k, v) in headers], "scheme": scheme.decode("ascii"), "path": unquote(path.decode("ascii")), "query_string": query, "server": (host.decode("ascii"), port), "client": self.client, "root_path": self.root_path, } # Request. request_body_chunks = stream.__aiter__() request_complete = False # Response. status_code = None response_headers = None body_parts = [] response_started = False response_complete = create_event() # ASGI callables. async def receive() -> dict: nonlocal request_complete if request_complete: await response_complete.wait() return {"type": "http.disconnect"} try: body = await request_body_chunks.__anext__() except StopAsyncIteration: request_complete = True return {"type": "http.request", "body": b"", "more_body": False} return {"type": "http.request", "body": body, "more_body": True} async def send(message: dict) -> None: nonlocal status_code, response_headers, response_started if message["type"] == "http.response.start": assert not response_started status_code = message["status"] response_headers = message.get("headers", []) response_started = True elif message["type"] == "http.response.body": assert not response_complete.is_set() body = message.get("body", b"") more_body = message.get("more_body", False) if body and method != b"HEAD": body_parts.append(body) if not more_body: response_complete.set() try: await self.app(scope, receive, send) except Exception: if self.raise_app_exceptions or not response_complete.is_set(): raise assert response_complete.is_set() assert status_code is not None assert response_headers is not None > stream = httpcore.PlainByteStream(content=b"".join(body_parts)) E AttributeError: module 'httpcore' has no attribute 'PlainByteStream' /usr/lib/python3/dist-packages/httpx/_transports/asgi.py:157: AttributeError ______________________________ test_async_testing ______________________________ @pytest.mark.asyncio async def test_async_testing(): > await test_root() tests/test_tutorial/test_async_tests/test_main.py:8: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/async_tests/test_main.py:10: in test_root response = await ac.get("/") /usr/lib/python3/dist-packages/httpx/_client.py:1548: in get return await self.request( /usr/lib/python3/dist-packages/httpx/_client.py:1371: in request response = await self.send( /usr/lib/python3/dist-packages/httpx/_client.py:1406: in send response = await self._send_handling_auth( /usr/lib/python3/dist-packages/httpx/_client.py:1444: in _send_handling_auth response = await self._send_handling_redirects( /usr/lib/python3/dist-packages/httpx/_client.py:1476: in _send_handling_redirects response = await self._send_single_request(request, timeout) /usr/lib/python3/dist-packages/httpx/_client.py:1502: in _send_single_request (status_code, headers, stream, ext,) = await transport.arequest( _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , method = b'GET' url = (b'http', b'test', None, b'/') headers = [(b'Host', b'test'), (b'Accept', b'*/*'), (b'Accept-Encoding', b'gzip, deflate'), (b'Connection', b'keep-alive'), (b'User-Agent', b'python-httpx/0.16.1')] stream = ext = {'timeout': {'connect': 5.0, 'pool': 5.0, 'read': 5.0, 'write': 5.0}} async def arequest( self, method: bytes, url: Tuple[bytes, bytes, Optional[int], bytes], headers: List[Tuple[bytes, bytes]] = None, stream: httpcore.AsyncByteStream = None, ext: dict = None, ) -> Tuple[int, List[Tuple[bytes, bytes]], httpcore.AsyncByteStream, dict]: headers = [] if headers is None else headers stream = httpcore.PlainByteStream(content=b"") if stream is None else stream # ASGI scope. scheme, host, port, full_path = url path, _, query = full_path.partition(b"?") scope = { "type": "http", "asgi": {"version": "3.0"}, "http_version": "1.1", "method": method.decode(), "headers": [(k.lower(), v) for (k, v) in headers], "scheme": scheme.decode("ascii"), "path": unquote(path.decode("ascii")), "query_string": query, "server": (host.decode("ascii"), port), "client": self.client, "root_path": self.root_path, } # Request. request_body_chunks = stream.__aiter__() request_complete = False # Response. status_code = None response_headers = None body_parts = [] response_started = False response_complete = create_event() # ASGI callables. async def receive() -> dict: nonlocal request_complete if request_complete: await response_complete.wait() return {"type": "http.disconnect"} try: body = await request_body_chunks.__anext__() except StopAsyncIteration: request_complete = True return {"type": "http.request", "body": b"", "more_body": False} return {"type": "http.request", "body": body, "more_body": True} async def send(message: dict) -> None: nonlocal status_code, response_headers, response_started if message["type"] == "http.response.start": assert not response_started status_code = message["status"] response_headers = message.get("headers", []) response_started = True elif message["type"] == "http.response.body": assert not response_complete.is_set() body = message.get("body", b"") more_body = message.get("more_body", False) if body and method != b"HEAD": body_parts.append(body) if not more_body: response_complete.set() try: await self.app(scope, receive, send) except Exception: if self.raise_app_exceptions or not response_complete.is_set(): raise assert response_complete.is_set() assert status_code is not None assert response_headers is not None > stream = httpcore.PlainByteStream(content=b"".join(body_parts)) E AttributeError: module 'httpcore' has no attribute 'PlainByteStream' /usr/lib/python3/dist-packages/httpx/_transports/asgi.py:157: AttributeError _____________________________________ test _____________________________________ def test(): log = Path("log.txt") if log.is_file(): os.remove(log) # pragma: no cover > response = client.post("/send-notification/foo@example.com") tests/test_tutorial/test_background_tasks/test_tutorial001.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/send-notification/foo@example.com', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________________ test _____________________________________ def test(): log = Path("log.txt") if log.is_file(): os.remove(log) # pragma: no cover > response = client.post("/send-notification/foo@example.com?q=some-query") tests/test_tutorial/test_background_tasks/test_tutorial002.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/send-notification/foo@example.com', query = 'q=some-query' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py:29: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py:35: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py:29: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py:35: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py:39: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_behind_a_proxy/test_tutorial004.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_tutorial/test_behind_a_proxy/test_tutorial004.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_get_path[/users?token=jessica-200-expected_response0-headers0] ______ path = '/users?token=jessica', expected_status = 200 expected_response = [{'username': 'Rick'}, {'username': 'Morty'}], headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users', query = 'token=jessica' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get_path[/users-422-expected_response1-headers1] _____________ path = '/users', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_get_path[/users/foo?token=jessica-200-expected_response2-headers2] ____ path = '/users/foo?token=jessica', expected_status = 200 expected_response = {'username': 'foo'}, headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/foo' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/users/foo-422-expected_response3-headers3] ___________ path = '/users/foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____ test_get_path[/users/me?token=jessica-200-expected_response4-headers4] ____ path = '/users/me?token=jessica', expected_status = 200 expected_response = {'username': 'fakecurrentuser'}, headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/users/me-422-expected_response5-headers5] ___________ path = '/users/me', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_get_path[/items?token=jessica-200-expected_response6-headers6] ______ path = '/items?token=jessica', expected_status = 200 expected_response = {'gun': {'name': 'Portal Gun'}, 'plumbus': {'name': 'Plumbus'}} headers = {'X-Token': 'fake-super-secret-token'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'token=jessica' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get_path[/items-422-expected_response7-headers7] _____________ path = '/items', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {'X-Token': 'fake-super-secret-token'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_get_path[/items/plumbus?token=jessica-200-expected_response8-headers8] __ path = '/items/plumbus?token=jessica', expected_status = 200 expected_response = {'item_id': 'plumbus', 'name': 'Plumbus'} headers = {'X-Token': 'fake-super-secret-token'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/plumbus' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/items/plumbus-422-expected_response9-headers9] _________ path = '/items/plumbus', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {'X-Token': 'fake-super-secret-token'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/plumbus', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____ test_get_path[/items?token=jessica-400-expected_response10-headers10] _____ path = '/items?token=jessica', expected_status = 400 expected_response = {'detail': 'X-Token header invalid'} headers = {'X-Token': 'invalid'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'token=jessica' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __ test_get_path[/items/bar?token=jessica-400-expected_response11-headers11] ___ path = '/items/bar?token=jessica', expected_status = 400 expected_response = {'detail': 'X-Token header invalid'} headers = {'X-Token': 'invalid'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____ test_get_path[/items?token=jessica-422-expected_response12-headers12] _____ path = '/items?token=jessica', expected_status = 422 expected_response = {'detail': [{'loc': ['header', 'x-token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'token=jessica' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_get_path[/items/plumbus?token=jessica-422-expected_response13-headers13] _ path = '/items/plumbus?token=jessica', expected_status = 422 expected_response = {'detail': [{'loc': ['header', 'x-token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/plumbus' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/?token=jessica-200-expected_response14-headers14] _______ path = '/?token=jessica', expected_status = 200 expected_response = {'message': 'Hello Bigger Applications!'}, headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = 'token=jessica' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_get_path[/-422-expected_response15-headers15] ______________ path = '/', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/openapi.json-200-expected_response16-headers16] ________ path = '/openapi.json', expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type...n': 'Not found'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Update Item', ...}}, ...}} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_put_no_header ______________________________ def test_put_no_header(): > response = client.put("/items/foo") tests/test_tutorial/test_bigger_applications/test_main.py:428: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_put_invalid_header ____________________________ def test_put_invalid_header(): > response = client.put("/items/foo", headers={"X-Token": "invalid"}) tests/test_tutorial/test_bigger_applications/test_main.py:447: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_put ___________________________________ def test_put(): > response = client.put( "/items/plumbus?token=jessica", headers={"X-Token": "fake-super-secret-token"} ) tests/test_tutorial/test_bigger_applications/test_main.py:453: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/plumbus' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_put_forbidden ______________________________ def test_put_forbidden(): > response = client.put( "/items/bar?token=jessica", headers={"X-Token": "fake-super-secret-token"} ) tests/test_tutorial/test_bigger_applications/test_main.py:461: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_admin __________________________________ def test_admin(): > response = client.post( "/admin/?token=jessica", headers={"X-Token": "fake-super-secret-token"} ) tests/test_tutorial/test_bigger_applications/test_main.py:469: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/admin/' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_admin_invalid_header ___________________________ def test_admin_invalid_header(): > response = client.post("/admin/", headers={"X-Token": "invalid"}) tests/test_tutorial/test_bigger_applications/test_main.py:477: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/admin/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body/test_tutorial001.py:89: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body0-200-expected_response0] _____________ path = '/items/', body = {'name': 'Foo', 'price': 50.5}, expected_status = 200 expected_response = {'description': None, 'name': 'Foo', 'price': 50.5, 'tax': None} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'30'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body1-200-expected_response1] _____________ path = '/items/', body = {'name': 'Foo', 'price': '50.5'}, expected_status = 200 expected_response = {'description': None, 'name': 'Foo', 'price': 50.5, 'tax': None} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'32'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body2-200-expected_response2] _____________ path = '/items/' body = {'description': 'Some Foo', 'name': 'Foo', 'price': '50.5'} expected_status = 200 expected_response = {'description': 'Some Foo', 'name': 'Foo', 'price': 50.5, 'tax': None} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'59'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body3-200-expected_response3] _____________ path = '/items/' body = {'description': 'Some Foo', 'name': 'Foo', 'price': '50.5', 'tax': 0.3} expected_status = 200 expected_response = {'description': 'Some Foo', 'name': 'Foo', 'price': 50.5, 'tax': 0.3} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'71'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body4-422-expected_response4] _____________ path = '/items/', body = {'name': 'Foo'}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'price'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body5-422-expected_response5] _____________ path = '/items/', body = {'name': 'Foo', 'price': 'twenty'} expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'price'], 'msg': 'value is not a valid float', 'type': 'type_error.float'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'34'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body6-422-expected_response6] _____________ path = '/items/', body = {}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'name'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', 'price'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'2'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-None-422-expected_response7] ______________ path = '/items/', body = None, expected_status = 422 expected_response = {'detail': [{'loc': ['body'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_broken_body _____________________________ def test_post_broken_body(): > response = client.post("/items/", data={"name": "Foo", "price": 50.5}) tests/test_tutorial/test_body/test_tutorial001.py:176: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'19'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body_fields/test_tutorial001.py:113: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items/5-body0-200-expected_response0] __________________ path = '/items/5', body = {'item': {'name': 'Foo', 'price': 3.0}} expected_status = 200 expected_response = {'item': {'description': None, 'name': 'Foo', 'price': 3.0, 'tax': None}, 'item_id': 5} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", {"item": {"name": "Foo", "price": 3.0}}, 200, { "item_id": 5, "item": {"name": "Foo", "price": 3.0, "description": None, "tax": None}, }, ), ( "/items/6", { "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": "5.4", } }, 200, { "item_id": 6, "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": 5.4, }, }, ), ("/items/5", {"item": {"name": "Foo", "price": -3.0}}, 422, price_not_greater), ], ) def test(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_fields/test_tutorial001.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'39'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items/6-body1-200-expected_response1] __________________ path = '/items/6' body = {'item': {'description': 'Some bar', 'name': 'Bar', 'price': 0.2, 'tax': '5.4'}} expected_status = 200 expected_response = {'item': {'description': 'Some bar', 'name': 'Bar', 'price': 0.2, 'tax': 5.4}, 'item_id': 6} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", {"item": {"name": "Foo", "price": 3.0}}, 200, { "item_id": 5, "item": {"name": "Foo", "price": 3.0, "description": None, "tax": None}, }, ), ( "/items/6", { "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": "5.4", } }, 200, { "item_id": 6, "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": 5.4, }, }, ), ("/items/5", {"item": {"name": "Foo", "price": -3.0}}, 422, price_not_greater), ], ) def test(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_fields/test_tutorial001.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/6', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'80'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items/5-body2-422-expected_response2] __________________ path = '/items/5', body = {'item': {'name': 'Foo', 'price': -3.0}} expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 0}, 'loc': ['body', 'item', 'price'], 'msg': 'ensure this value is greater than 0', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", {"item": {"name": "Foo", "price": 3.0}}, 200, { "item_id": 5, "item": {"name": "Foo", "price": 3.0, "description": None, "tax": None}, }, ), ( "/items/6", { "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": "5.4", } }, 200, { "item_id": 6, "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": 5.4, }, }, ), ("/items/5", {"item": {"name": "Foo", "price": -3.0}}, 422, price_not_greater), ], ) def test(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_fields/test_tutorial001.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'40'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body_multiple_params/test_tutorial001.py:105: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_post_body[/items/5?q=bar-body0-200-expected_response0] __________ path = '/items/5?q=bar', body = {'name': 'Foo', 'price': 50.5} expected_status = 200 expected_response = {'item': {'description': None, 'name': 'Foo', 'price': 50.5, 'tax': None}, 'item_id': 5, 'q': 'bar'} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5?q=bar", {"name": "Foo", "price": 50.5}, 200, { "item_id": 5, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "q": "bar", }, ), ("/items/5?q=bar", None, 200, {"item_id": 5, "q": "bar"}), ("/items/5", None, 200, {"item_id": 5}), ("/items/foo", None, 422, item_id_not_int), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial001.py:145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = 'q=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'30'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_post_body[/items/5?q=bar-None-200-expected_response1] __________ path = '/items/5?q=bar', body = None, expected_status = 200 expected_response = {'item_id': 5, 'q': 'bar'} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5?q=bar", {"name": "Foo", "price": 50.5}, 200, { "item_id": 5, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "q": "bar", }, ), ("/items/5?q=bar", None, 200, {"item_id": 5, "q": "bar"}), ("/items/5", None, 200, {"item_id": 5}), ("/items/foo", None, 422, item_id_not_int), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial001.py:145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = 'q=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/5-None-200-expected_response2] _____________ path = '/items/5', body = None, expected_status = 200 expected_response = {'item_id': 5} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5?q=bar", {"name": "Foo", "price": 50.5}, 200, { "item_id": 5, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "q": "bar", }, ), ("/items/5?q=bar", None, 200, {"item_id": 5, "q": "bar"}), ("/items/5", None, 200, {"item_id": 5}), ("/items/foo", None, 422, item_id_not_int), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial001.py:145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_post_body[/items/foo-None-422-expected_response3] ____________ path = '/items/foo', body = None, expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5?q=bar", {"name": "Foo", "price": 50.5}, 200, { "item_id": 5, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "q": "bar", }, ), ("/items/5?q=bar", None, 200, {"item_id": 5, "q": "bar"}), ("/items/5", None, 200, {"item_id": 5}), ("/items/foo", None, 422, item_id_not_int), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial001.py:145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body_multiple_params/test_tutorial003.py:116: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_post_body[/items/5-body0-200-expected_response0] _____________ path = '/items/5' body = {'importance': 2, 'item': {'name': 'Foo', 'price': 50.5}, 'user': {'username': 'Dave'}} expected_status = 200 expected_response = {'importance': 2, 'item': {'description': None, 'name': 'Foo', 'price': 50.5, 'tax': None}, 'item_id': 5, 'user': {'full_name': None, 'username': 'Dave'}} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", { "importance": 2, "item": {"name": "Foo", "price": 50.5}, "user": {"username": "Dave"}, }, 200, { "item_id": 5, "importance": 2, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "user": {"username": "Dave", "full_name": None}, }, ), ( "/items/5", None, 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ( "/items/5", [], 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial003.py:196: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'87'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/5-None-422-expected_response1] _____________ path = '/items/5', body = None, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'item'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', 'user'...ype': 'value_error.missing'}, {'loc': ['body', 'importance'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", { "importance": 2, "item": {"name": "Foo", "price": 50.5}, "user": {"username": "Dave"}, }, 200, { "item_id": 5, "importance": 2, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "user": {"username": "Dave", "full_name": None}, }, ), ( "/items/5", None, 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ( "/items/5", [], 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial003.py:196: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_post_body[/items/5-body2-422-expected_response2] _____________ path = '/items/5', body = [], expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'item'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', 'user'...ype': 'value_error.missing'}, {'loc': ['body', 'importance'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", { "importance": 2, "item": {"name": "Foo", "price": 50.5}, "user": {"username": "Dave"}, }, 200, { "item_id": 5, "importance": 2, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "user": {"username": "Dave", "full_name": None}, }, ), ( "/items/5", None, 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ( "/items/5", [], 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial003.py:196: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'2'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body_nested_models/test_tutorial009.py:79: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_post_body ________________________________ def test_post_body(): data = {"2": 2.2, "3": 3.3} > response = client.post("/index-weights/", json=data) tests/test_tutorial/test_body_nested_models/test_tutorial009.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/index-weights/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'20'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_invalid_body ____________________________ def test_post_invalid_body(): data = {"foo": 2.2, "3": 3.3} > response = client.post("/index-weights/", json=data) tests/test_tutorial/test_body_nested_models/test_tutorial009.py:93: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/index-weights/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'22'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body_updates/test_tutorial001.py:135: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/baz") tests/test_tutorial/test_body_updates/test_tutorial001.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/baz', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_put ___________________________________ def test_put(): > response = client.put( "/items/bar", json={"name": "Barz", "price": 3, "description": None} ) tests/test_tutorial/test_body_updates/test_tutorial001.py:153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'49'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_default_openapi _____________________________ def test_default_openapi(): client = TestClient(tutorial001.app) > response = client.get("/openapi.json") tests/test_tutorial/test_conditional_openapi/test_tutorial001.py:29: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_disable_openapi _____________________________ monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f8a36dc09a0> def test_disable_openapi(monkeypatch): monkeypatch.setenv("OPENAPI_URL", "") importlib.reload(tutorial001) client = TestClient(tutorial001.app) > response = client.get("/openapi.json") tests/test_tutorial/test_conditional_openapi/test_tutorial001.py:41: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test[/openapi.json-None-200-expected_response0] ________________ path = '/openapi.json', cookies = None, expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type...on': 'Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Read Items'}}}} @pytest.mark.parametrize( "path,cookies,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"ads_id": None}), ("/items", {"ads_id": "ads_track"}, 200, {"ads_id": "ads_track"}), ( "/items", {"ads_id": "ads_track", "session": "cookiesession"}, 200, {"ads_id": "ads_track"}, ), ("/items", {"session": "cookiesession"}, 200, {"ads_id": None}), ], ) def test(path, cookies, expected_status, expected_response): > response = client.get(path, cookies=cookies) tests/test_tutorial/test_cookie_params/test_tutorial001.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test[/items-None-200-expected_response1] ___________________ path = '/items', cookies = None, expected_status = 200 expected_response = {'ads_id': None} @pytest.mark.parametrize( "path,cookies,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"ads_id": None}), ("/items", {"ads_id": "ads_track"}, 200, {"ads_id": "ads_track"}), ( "/items", {"ads_id": "ads_track", "session": "cookiesession"}, 200, {"ads_id": "ads_track"}, ), ("/items", {"session": "cookiesession"}, 200, {"ads_id": None}), ], ) def test(path, cookies, expected_status, expected_response): > response = client.get(path, cookies=cookies) tests/test_tutorial/test_cookie_params/test_tutorial001.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items-cookies2-200-expected_response2] _________________ path = '/items', cookies = {'ads_id': 'ads_track'}, expected_status = 200 expected_response = {'ads_id': 'ads_track'} @pytest.mark.parametrize( "path,cookies,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"ads_id": None}), ("/items", {"ads_id": "ads_track"}, 200, {"ads_id": "ads_track"}), ( "/items", {"ads_id": "ads_track", "session": "cookiesession"}, 200, {"ads_id": "ads_track"}, ), ("/items", {"session": "cookiesession"}, 200, {"ads_id": None}), ], ) def test(path, cookies, expected_status, expected_response): > response = client.get(path, cookies=cookies) tests/test_tutorial/test_cookie_params/test_tutorial001.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'cookie', b'ads_id=ads_track')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items-cookies3-200-expected_response3] _________________ path = '/items', cookies = {'ads_id': 'ads_track', 'session': 'cookiesession'} expected_status = 200, expected_response = {'ads_id': 'ads_track'} @pytest.mark.parametrize( "path,cookies,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"ads_id": None}), ("/items", {"ads_id": "ads_track"}, 200, {"ads_id": "ads_track"}), ( "/items", {"ads_id": "ads_track", "session": "cookiesession"}, 200, {"ads_id": "ads_track"}, ), ("/items", {"session": "cookiesession"}, 200, {"ads_id": None}), ], ) def test(path, cookies, expected_status, expected_response): > response = client.get(path, cookies=cookies) tests/test_tutorial/test_cookie_params/test_tutorial001.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'cookie', b'ads_id=ads_track; session=cookiesession')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items-cookies4-200-expected_response4] _________________ path = '/items', cookies = {'session': 'cookiesession'}, expected_status = 200 expected_response = {'ads_id': None} @pytest.mark.parametrize( "path,cookies,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"ads_id": None}), ("/items", {"ads_id": "ads_track"}, 200, {"ads_id": "ads_track"}), ( "/items", {"ads_id": "ads_track", "session": "cookiesession"}, 200, {"ads_id": "ads_track"}, ), ("/items", {"session": "cookiesession"}, 200, {"ads_id": None}), ], ) def test(path, cookies, expected_status, expected_response): > response = client.get(path, cookies=cookies) tests/test_tutorial/test_cookie_params/test_tutorial001.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'cookie', b'session=cookiesession')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_cors ___________________________________ def test_cors(): client = TestClient(app) # Test pre-flight response headers = { "Origin": "https://localhost.tiangolo.com", "Access-Control-Request-Method": "GET", "Access-Control-Request-Headers": "X-Example", } > response = client.options("/", headers=headers) tests/test_tutorial/test_cors/test_tutorial001.py:14: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:566: in options return self.request('OPTIONS', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'origin', b'https://localhost.tiangolo.com'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_gzip_request[True] ____________________________ compress = True @pytest.mark.parametrize("compress", [True, False]) def test_gzip_request(compress): n = 1000 headers = {} body = [1] * n data = json.dumps(body).encode() if compress: data = gzip.compress(data) headers["Content-Encoding"] = "gzip" > response = client.post("/sum", data=data, headers=headers) tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sum', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-encoding', b'gzip'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_gzip_request[False] ___________________________ compress = False @pytest.mark.parametrize("compress", [True, False]) def test_gzip_request(compress): n = 1000 headers = {} body = [1] * n data = json.dumps(body).encode() if compress: data = gzip.compress(data) headers["Content-Encoding"] = "gzip" > response = client.post("/sum", data=data, headers=headers) tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sum', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'3000')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_request_class ______________________________ def test_request_class(): > response = client.get("/check-class") tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/check-class', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_endpoint_works ______________________________ def test_endpoint_works(): > response = client.post("/", json=[1, 2, 3]) tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'9'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_exception_handler_body_access ______________________ def test_exception_handler_body_access(): > response = client.post("/", json={"numbers": [1, 2, 3]}) tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py:14: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'22'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/") tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_timed ________________________________ def test_get_timed(): > response = client.get("/timed") tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/timed', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_custom_response/test_tutorial001.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_custom_response/test_tutorial001b.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_custom_response/test_tutorial004.py:39: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_custom_response/test_tutorial005.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/") tests/test_tutorial/test_custom_response/test_tutorial005.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/typer", allow_redirects=False) tests/test_tutorial/test_custom_response/test_tutorial006.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/typer', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): fake_content = b"some fake video bytes" > response = client.get("/") tests/test_tutorial/test_custom_response/test_tutorial007.py:10: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ tmp_path = PosixPath('/tmp/pytest-of-buildd/pytest-0/test_get0') def test_get(tmp_path: Path): file_path: Path = tmp_path / "large-video-file.mp4" tutorial008.some_file_path = str(file_path) test_content = b"Fake video bytes" file_path.write_bytes(test_content) > response = client.get("/") tests/test_tutorial/test_custom_response/test_tutorial008.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_dependencies/test_tutorial001.py:130: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get[/items-200-expected_response0] ____________________ path = '/items', expected_status = 200 expected_response = {'limit': 100, 'q': None, 'skip': 0} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_get[/items?q=foo-200-expected_response1] _________________ path = '/items?q=foo', expected_status = 200 expected_response = {'limit': 100, 'q': 'foo', 'skip': 0} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get[/items?q=foo&skip=5-200-expected_response2] _____________ path = '/items?q=foo&skip=5', expected_status = 200 expected_response = {'limit': 100, 'q': 'foo', 'skip': 5} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'q=foo&skip=5' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get[/items?q=foo&skip=5&limit=30-200-expected_response3] _________ path = '/items?q=foo&skip=5&limit=30', expected_status = 200 expected_response = {'limit': 30, 'q': 'foo', 'skip': 5} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items' query = 'q=foo&skip=5&limit=30', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get[/users-200-expected_response4] ____________________ path = '/users', expected_status = 200 expected_response = {'limit': 100, 'q': None, 'skip': 0} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_get[/openapi.json-200-expected_response5] ________________ path = '/openapi.json', expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type...on': 'Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Read Users'}}}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_dependencies/test_tutorial004.py:88: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get[/items-200-expected_response0] ____________________ path = '/items', expected_status = 200 expected_response = {'items': [{'item_name': 'Foo'}, {'item_name': 'Bar'}, {'item_name': 'Baz'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_get[/items?q=foo-200-expected_response1] _________________ path = '/items?q=foo', expected_status = 200 expected_response = {'items': [{'item_name': 'Foo'}, {'item_name': 'Bar'}, {'item_name': 'Baz'}], 'q': 'foo'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get[/items?q=foo&skip=1-200-expected_response2] _____________ path = '/items?q=foo&skip=1', expected_status = 200 expected_response = {'items': [{'item_name': 'Bar'}, {'item_name': 'Baz'}], 'q': 'foo'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'q=foo&skip=1' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get[/items?q=bar&limit=2-200-expected_response3] _____________ path = '/items?q=bar&limit=2', expected_status = 200 expected_response = {'items': [{'item_name': 'Foo'}, {'item_name': 'Bar'}], 'q': 'bar'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'q=bar&limit=2' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get[/items?q=bar&skip=1&limit=1-200-expected_response4] _________ path = '/items?q=bar&skip=1&limit=1', expected_status = 200 expected_response = {'items': [{'item_name': 'Bar'}], 'q': 'bar'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items' query = 'q=bar&skip=1&limit=1', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get[/items?limit=1&q=bar&skip=1-200-expected_response5] _________ path = '/items?limit=1&q=bar&skip=1', expected_status = 200 expected_response = {'items': [{'item_name': 'Bar'}], 'q': 'bar'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items' query = 'limit=1&q=bar&skip=1', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_dependencies/test_tutorial006.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_no_headers ______________________________ def test_get_no_headers(): > response = client.get("/items/") tests/test_tutorial/test_dependencies/test_tutorial006.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_get_invalid_one_header __________________________ def test_get_invalid_one_header(): > response = client.get("/items/", headers={"X-Token": "invalid"}) tests/test_tutorial/test_dependencies/test_tutorial006.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_get_invalid_second_header ________________________ def test_get_invalid_second_header(): > response = client.get( "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"} ) tests/test_tutorial/test_dependencies/test_tutorial006.py:112: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_get_valid_headers ____________________________ def test_get_valid_headers(): > response = client.get( "/items/", headers={ "X-Token": "fake-super-secret-token", "X-Key": "fake-super-secret-key", }, ) tests/test_tutorial/test_dependencies/test_tutorial006.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_dependencies/test_tutorial012.py:117: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get_no_headers_items ___________________________ def test_get_no_headers_items(): > response = client.get("/items/") tests/test_tutorial/test_dependencies/test_tutorial012.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get_no_headers_users ___________________________ def test_get_no_headers_users(): > response = client.get("/users/") tests/test_tutorial/test_dependencies/test_tutorial012.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_get_invalid_one_header_items _______________________ def test_get_invalid_one_header_items(): > response = client.get("/items/", headers={"X-Token": "invalid"}) tests/test_tutorial/test_dependencies/test_tutorial012.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get_invalid_one_users __________________________ def test_get_invalid_one_users(): > response = client.get("/users/", headers={"X-Token": "invalid"}) tests/test_tutorial/test_dependencies/test_tutorial012.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_get_invalid_second_header_items _____________________ def test_get_invalid_second_header_items(): > response = client.get( "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"} ) tests/test_tutorial/test_dependencies/test_tutorial012.py:173: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_get_invalid_second_header_users _____________________ def test_get_invalid_second_header_users(): > response = client.get( "/users/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"} ) tests/test_tutorial/test_dependencies/test_tutorial012.py:181: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_get_valid_headers_items _________________________ def test_get_valid_headers_items(): > response = client.get( "/items/", headers={ "X-Token": "fake-super-secret-token", "X-Key": "fake-super-secret-key", }, ) tests/test_tutorial/test_dependencies/test_tutorial012.py:189: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_get_valid_headers_users _________________________ def test_get_valid_headers_users(): > response = client.get( "/users/", headers={ "X-Token": "fake-super-secret-token", "X-Key": "fake-super-secret-key", }, ) tests/test_tutorial/test_dependencies/test_tutorial012.py:201: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_events __________________________________ def test_events(): > with TestClient(app) as client: tests/test_tutorial/test_events/test_tutorial001.py:73: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _________________________________ test_events __________________________________ def test_events(): > with TestClient(app) as client: tests/test_tutorial/test_events/test_tutorial002.py:26: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_extending_openapi/test_tutorial001.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________________ test _____________________________________ def test(): > response = client.get("/items/") tests/test_tutorial/test_extending_openapi/test_tutorial001.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_extra_data_types/test_tutorial001.py:115: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_extra_types _______________________________ def test_extra_types(): item_id = "ff97dd87-a4a5-4a12-b412-cde99f33e00e" data = { "start_datetime": "2018-12-22T14:00:00+00:00", "end_datetime": "2018-12-24T15:00:00+00:00", "repeat_at": "15:30:00", "process_after": 300, } expected_response = data.copy() expected_response.update( { "start_process": "2018-12-22T14:05:00+00:00", "duration": 176_100, "item_id": item_id, } ) > response = client.put(f"/items/{item_id}", json=data) tests/test_tutorial/test_extra_data_types/test_tutorial001.py:136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/items/ff97dd87-a4a5-4a12-b412-cde99f33e00e', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'139'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_extra_models/test_tutorial003.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_get_car _________________________________ def test_get_car(): > response = client.get("/items/item1") tests/test_tutorial/test_extra_models/test_tutorial003.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/item1', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_plane ________________________________ def test_get_plane(): > response = client.get("/items/item2") tests/test_tutorial/test_extra_models/test_tutorial003.py:119: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/item2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_extra_models/test_tutorial004.py:49: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_items ________________________________ def test_get_items(): > response = client.get("/items/") tests/test_tutorial/test_extra_models/test_tutorial004.py:55: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_extra_models/test_tutorial005.py:36: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_items ________________________________ def test_get_items(): > response = client.get("/keyword-weights/") tests/test_tutorial/test_extra_models/test_tutorial005.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/keyword-weights/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/-200-expected_response0] ____________________ path = '/', expected_status = 200 expected_response = {'message': 'Hello World'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_first_steps/test_tutorial001.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_get_path[/nonexistent-404-expected_response1] ______________ path = '/nonexistent', expected_status = 404 expected_response = {'detail': 'Not Found'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_first_steps/test_tutorial001.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/nonexistent', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/openapi.json-200-expected_response2] ______________ path = '/openapi.json', expected_status = 200 expected_response = {'info': {'title': 'FastAPI', 'version': '0.1.0'}, 'openapi': '3.0.2', 'paths': {'/': {'get': {'operationId': 'root__get', 'responses': {'200': {'content': {...}, 'description': 'Successful Response'}}, 'summary': 'Root'}}}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_first_steps/test_tutorial001.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial001.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_item _________________________________ def test_get_item(): > response = client.get("/items/foo") tests/test_tutorial/test_handling_errors/test_tutorial001.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_get_item_not_found ____________________________ def test_get_item_not_found(): > response = client.get("/items/bar") tests/test_tutorial/test_handling_errors/test_tutorial001.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial002.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_item_header _____________________________ def test_get_item_header(): > response = client.get("/items-header/foo") tests/test_tutorial/test_handling_errors/test_tutorial002.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items-header/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_get_item_not_found_header ________________________ def test_get_item_not_found_header(): > response = client.get("/items-header/bar") tests/test_tutorial/test_handling_errors/test_tutorial002.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items-header/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial003.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/unicorns/shinny") tests/test_tutorial/test_handling_errors/test_tutorial003.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/unicorns/shinny', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_get_exception ______________________________ def test_get_exception(): > response = client.get("/unicorns/yolo") tests/test_tutorial/test_handling_errors/test_tutorial003.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/unicorns/yolo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial004.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get_validation_error ___________________________ def test_get_validation_error(): > response = client.get("/items/foo") tests/test_tutorial/test_handling_errors/test_tutorial004.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_http_error ______________________________ def test_get_http_error(): > response = client.get("/items/3") tests/test_tutorial/test_handling_errors/test_tutorial004.py:92: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/3', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/2") tests/test_tutorial/test_handling_errors/test_tutorial004.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial005.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_post_validation_error __________________________ def test_post_validation_error(): > response = client.post("/items/", json={"title": "towel", "size": "XL"}) tests/test_tutorial/test_handling_errors/test_tutorial005.py:90: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'32'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_post ___________________________________ def test_post(): data = {"title": "towel", "size": 5} > response = client.post("/items/", json=data) tests/test_tutorial/test_handling_errors/test_tutorial005.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'29'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial006.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get_validation_error ___________________________ def test_get_validation_error(): > response = client.get("/items/foo") tests/test_tutorial/test_handling_errors/test_tutorial006.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_http_error ______________________________ def test_get_http_error(): > response = client.get("/items/3") tests/test_tutorial/test_handling_errors/test_tutorial006.py:95: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/3', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/2") tests/test_tutorial/test_handling_errors/test_tutorial006.py:101: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test[/openapi.json-None-200-expected_response0] ________________ path = '/openapi.json', headers = None, expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type...on': 'Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Read Items'}}}} @pytest.mark.parametrize( "path,headers,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"User-Agent": "testclient"}), ("/items", {"X-Header": "notvalid"}, 200, {"User-Agent": "testclient"}), ("/items", {"User-Agent": "FastAPI test"}, 200, {"User-Agent": "FastAPI test"}), ], ) def test(path, headers, expected_status, expected_response): > response = client.get(path, headers=headers) tests/test_tutorial/test_header_params/test_tutorial001.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test[/items-None-200-expected_response1] ___________________ path = '/items', headers = None, expected_status = 200 expected_response = {'User-Agent': 'testclient'} @pytest.mark.parametrize( "path,headers,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"User-Agent": "testclient"}), ("/items", {"X-Header": "notvalid"}, 200, {"User-Agent": "testclient"}), ("/items", {"User-Agent": "FastAPI test"}, 200, {"User-Agent": "FastAPI test"}), ], ) def test(path, headers, expected_status, expected_response): > response = client.get(path, headers=headers) tests/test_tutorial/test_header_params/test_tutorial001.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items-headers2-200-expected_response2] _________________ path = '/items', headers = {'X-Header': 'notvalid'}, expected_status = 200 expected_response = {'User-Agent': 'testclient'} @pytest.mark.parametrize( "path,headers,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"User-Agent": "testclient"}), ("/items", {"X-Header": "notvalid"}, 200, {"User-Agent": "testclient"}), ("/items", {"User-Agent": "FastAPI test"}, 200, {"User-Agent": "FastAPI test"}), ], ) def test(path, headers, expected_status, expected_response): > response = client.get(path, headers=headers) tests/test_tutorial/test_header_params/test_tutorial001.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-header', b'notvalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items-headers3-200-expected_response3] _________________ path = '/items', headers = {'User-Agent': 'FastAPI test'}, expected_status = 200 expected_response = {'User-Agent': 'FastAPI test'} @pytest.mark.parametrize( "path,headers,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"User-Agent": "testclient"}), ("/items", {"X-Header": "notvalid"}, 200, {"User-Agent": "testclient"}), ("/items", {"User-Agent": "FastAPI test"}, 200, {"User-Agent": "FastAPI test"}), ], ) def test(path, headers, expected_status, expected_response): > response = client.get(path, headers=headers) tests/test_tutorial/test_header_params/test_tutorial001.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'FastAPI test'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_metadata/test_tutorial001.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_items __________________________________ def test_items(): > response = client.get("/items/") tests/test_tutorial/test_metadata/test_tutorial001.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_metadata/test_tutorial004.py:56: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operations _____________________________ def test_path_operations(): > response = client.get("/items/") tests/test_tutorial/test_metadata/test_tutorial004.py:62: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > with client: tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py:158: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.post( "/invoices/", json={"id": "fooinvoice", "customer": "John", "total": 5.3} ) tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py:165: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/invoices/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'54'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial001.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial001.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial002.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial002.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial003.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial003.py:21: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_query_params_str_validations _______________________ def test_query_params_str_validations(): > response = client.post("/items/", json={"name": "Foo", "price": 42}) tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'28'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_query_params_str_validations _______________________ def test_query_params_str_validations(): > response = client.post("/items/", json={"name": "Foo", "price": 42}) tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'28'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py:57: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______ test_query_params_str_validations[/items/-200-expected_response0] _______ path = '/items/', expected_status = 200 expected_response = [{'name': 'Foo', 'price': 42}] @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items/", 200, [{"name": "Foo", "price": 42}]), ("/users/", 200, [{"username": "johndoe"}]), ("/elements/", 200, [{"item_id": "Foo"}]), ], ) def test_query_params_str_validations(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py:71: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______ test_query_params_str_validations[/users/-200-expected_response1] _______ path = '/users/', expected_status = 200 expected_response = [{'username': 'johndoe'}] @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items/", 200, [{"name": "Foo", "price": 42}]), ("/users/", 200, [{"username": "johndoe"}]), ("/elements/", 200, [{"item_id": "Foo"}]), ], ) def test_query_params_str_validations(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py:71: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_query_params_str_validations[/elements/-200-expected_response2] _____ path = '/elements/', expected_status = 200 expected_response = [{'item_id': 'Foo'}] @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items/", 200, [{"name": "Foo", "price": 42}]), ("/users/", 200, [{"username": "johndoe"}]), ("/elements/", 200, [{"item_id": "Foo"}]), ], ) def test_query_params_str_validations(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py:71: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/elements/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_params/test_tutorial004.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_file_path ________________________________ def test_file_path(): > response = client.get("/files/home/johndoe/myfile.txt") tests/test_tutorial/test_path_params/test_tutorial004.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/home/johndoe/myfile.txt' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_root_file_path ______________________________ def test_root_file_path(): > response = client.get("/files//home/johndoe/myfile.txt") tests/test_tutorial/test_path_params/test_tutorial004.py:88: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files//home/johndoe/myfile.txt' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_params/test_tutorial005.py:153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_get_enums[/models/alexnet-200-expected0] _________________ url = '/models/alexnet', status_code = 200 expected = {'message': 'Deep Learning FTW!', 'model_name': 'alexnet'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/models/alexnet", 200, {"model_name": "alexnet", "message": "Deep Learning FTW!"}, ), ( "/models/lenet", 200, {"model_name": "lenet", "message": "LeCNN all the images"}, ), ( "/models/resnet", 200, {"model_name": "resnet", "message": "Have some residuals"}, ), ( "/models/foo", 422, { "detail": [ { "ctx": {"enum_values": ["alexnet", "resnet", "lenet"]}, "loc": ["path", "model_name"], "msg": "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'", "type": "type_error.enum", } ] }, ), ], ) def test_get_enums(url, status_code, expected): > response = client.get(url) tests/test_tutorial/test_path_params/test_tutorial005.py:194: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/models/alexnet', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_enums[/models/lenet-200-expected1] __________________ url = '/models/lenet', status_code = 200 expected = {'message': 'LeCNN all the images', 'model_name': 'lenet'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/models/alexnet", 200, {"model_name": "alexnet", "message": "Deep Learning FTW!"}, ), ( "/models/lenet", 200, {"model_name": "lenet", "message": "LeCNN all the images"}, ), ( "/models/resnet", 200, {"model_name": "resnet", "message": "Have some residuals"}, ), ( "/models/foo", 422, { "detail": [ { "ctx": {"enum_values": ["alexnet", "resnet", "lenet"]}, "loc": ["path", "model_name"], "msg": "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'", "type": "type_error.enum", } ] }, ), ], ) def test_get_enums(url, status_code, expected): > response = client.get(url) tests/test_tutorial/test_path_params/test_tutorial005.py:194: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/models/lenet', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_enums[/models/resnet-200-expected2] _________________ url = '/models/resnet', status_code = 200 expected = {'message': 'Have some residuals', 'model_name': 'resnet'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/models/alexnet", 200, {"model_name": "alexnet", "message": "Deep Learning FTW!"}, ), ( "/models/lenet", 200, {"model_name": "lenet", "message": "LeCNN all the images"}, ), ( "/models/resnet", 200, {"model_name": "resnet", "message": "Have some residuals"}, ), ( "/models/foo", 422, { "detail": [ { "ctx": {"enum_values": ["alexnet", "resnet", "lenet"]}, "loc": ["path", "model_name"], "msg": "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'", "type": "type_error.enum", } ] }, ), ], ) def test_get_enums(url, status_code, expected): > response = client.get(url) tests/test_tutorial/test_path_params/test_tutorial005.py:194: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/models/resnet', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_enums[/models/foo-422-expected3] ___________________ url = '/models/foo', status_code = 422 expected = {'detail': [{'ctx': {'enum_values': ['alexnet', 'resnet', 'lenet']}, 'loc': ['path', 'model_name'], 'msg': "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'", 'type': 'type_error.enum'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/models/alexnet", 200, {"model_name": "alexnet", "message": "Deep Learning FTW!"}, ), ( "/models/lenet", 200, {"model_name": "lenet", "message": "LeCNN all the images"}, ), ( "/models/resnet", 200, {"model_name": "resnet", "message": "Have some residuals"}, ), ( "/models/foo", 422, { "detail": [ { "ctx": {"enum_values": ["alexnet", "resnet", "lenet"]}, "loc": ["path", "model_name"], "msg": "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'", "type": "type_error.enum", } ] }, ), ], ) def test_get_enums(url, status_code, expected): > response = client.get(url) tests/test_tutorial/test_path_params/test_tutorial005.py:194: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/models/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test[/openapi.json-200-expected_response0] __________________ path = '/openapi.json', expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type... 'Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Read User Item'}}}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ("/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very"}), ("/items/foo", 422, query_required), ("/items/foo", 422, query_required), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial005.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test[/items/foo?needy=very-200-expected_response1] ______________ path = '/items/foo?needy=very', expected_status = 200 expected_response = {'item_id': 'foo', 'needy': 'very'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ("/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very"}), ("/items/foo", 422, query_required), ("/items/foo", 422, query_required), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial005.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo' query = 'needy=very', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test[/items/foo-422-expected_response2] ____________________ path = '/items/foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'needy'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ("/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very"}), ("/items/foo", 422, query_required), ("/items/foo", 422, query_required), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial005.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test[/items/foo-422-expected_response3] ____________________ path = '/items/foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'needy'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ("/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very"}), ("/items/foo", 422, query_required), ("/items/foo", 422, query_required), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial005.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test[/openapi.json-200-expected_response0] __________________ path = '/openapi.json', expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type... 'Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Read User Item'}}}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ( "/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very", "skip": 0, "limit": None}, ), ( "/items/foo?skip=a&limit=b", 422, { "detail": [ { "loc": ["query", "needy"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["query", "skip"], "msg": "value is not a valid integer", "type": "type_error.integer", }, { "loc": ["query", "limit"], "msg": "value is not a valid integer", "type": "type_error.integer", }, ] }, ), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial006.py:139: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test[/items/foo?needy=very-200-expected_response1] ______________ path = '/items/foo?needy=very', expected_status = 200 expected_response = {'item_id': 'foo', 'limit': None, 'needy': 'very', 'skip': 0} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ( "/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very", "skip": 0, "limit": None}, ), ( "/items/foo?skip=a&limit=b", 422, { "detail": [ { "loc": ["query", "needy"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["query", "skip"], "msg": "value is not a valid integer", "type": "type_error.integer", }, { "loc": ["query", "limit"], "msg": "value is not a valid integer", "type": "type_error.integer", }, ] }, ), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial006.py:139: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo' query = 'needy=very', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test[/items/foo?skip=a&limit=b-422-expected_response2] ____________ path = '/items/foo?skip=a&limit=b', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'needy'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['query', 'sk...ype_error.integer'}, {'loc': ['query', 'limit'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ( "/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very", "skip": 0, "limit": None}, ), ( "/items/foo?skip=a&limit=b", 422, { "detail": [ { "loc": ["query", "needy"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["query", "skip"], "msg": "value is not a valid integer", "type": "type_error.integer", }, { "loc": ["query", "limit"], "msg": "value is not a valid integer", "type": "type_error.integer", }, ] }, ), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial006.py:139: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo' query = 'skip=a&limit=b', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py:85: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_query_params_str_validations[None-None-200-expected_response0] ______ q_name = None, q = None, expected_status = 200 expected_response = {'items': [{'item_id': 'Foo'}, {'item_id': 'Bar'}]} @pytest.mark.parametrize( "q_name,q,expected_status,expected_response", [ (None, None, 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ( "item-query", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}], "q": "fixedquery"}, ), ("q", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ("item-query", "nonregexquery", 422, regex_error), ], ) def test_query_params_str_validations(q_name, q, expected_status, expected_response): url = "/items/" if q_name and q: url = f"{url}?{q_name}={q}" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_query_params_str_validations[item-query-fixedquery-200-expected_response1] _ q_name = 'item-query', q = 'fixedquery', expected_status = 200 expected_response = {'items': [{'item_id': 'Foo'}, {'item_id': 'Bar'}], 'q': 'fixedquery'} @pytest.mark.parametrize( "q_name,q,expected_status,expected_response", [ (None, None, 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ( "item-query", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}], "q": "fixedquery"}, ), ("q", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ("item-query", "nonregexquery", 422, regex_error), ], ) def test_query_params_str_validations(q_name, q, expected_status, expected_response): url = "/items/" if q_name and q: url = f"{url}?{q_name}={q}" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'item-query=fixedquery', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____ test_query_params_str_validations[q-fixedquery-200-expected_response2] ____ q_name = 'q', q = 'fixedquery', expected_status = 200 expected_response = {'items': [{'item_id': 'Foo'}, {'item_id': 'Bar'}]} @pytest.mark.parametrize( "q_name,q,expected_status,expected_response", [ (None, None, 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ( "item-query", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}], "q": "fixedquery"}, ), ("q", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ("item-query", "nonregexquery", 422, regex_error), ], ) def test_query_params_str_validations(q_name, q, expected_status, expected_response): url = "/items/" if q_name and q: url = f"{url}?{q_name}={q}" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=fixedquery' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_query_params_str_validations[item-query-nonregexquery-422-expected_response3] _ q_name = 'item-query', q = 'nonregexquery', expected_status = 422 expected_response = {'detail': [{'ctx': {'pattern': '^fixedquery$'}, 'loc': ['query', 'item-query'], 'msg': 'string does not match regex "^fixedquery$"', 'type': 'value_error.str.regex'}]} @pytest.mark.parametrize( "q_name,q,expected_status,expected_response", [ (None, None, 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ( "item-query", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}], "q": "fixedquery"}, ), ("q", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ("item-query", "nonregexquery", 422, regex_error), ], ) def test_query_params_str_validations(q_name, q, expected_status, expected_response): url = "/items/" if q_name and q: url = f"{url}?{q_name}={q}" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'item-query=nonregexquery', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py:79: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_multi_query_values ____________________________ def test_multi_query_values(): url = "/items/?q=foo&q=bar" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=foo&q=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_query_no_values _____________________________ def test_query_no_values(): url = "/items/" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py:93: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py:80: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_default_query_values ___________________________ def test_default_query_values(): url = "/items/" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_multi_query_values ____________________________ def test_multi_query_values(): url = "/items/?q=baz&q=foobar" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py:94: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'q=baz&q=foobar', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py:80: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_multi_query_values ____________________________ def test_multi_query_values(): url = "/items/?q=foo&q=bar" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=foo&q=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_query_no_values _____________________________ def test_query_no_values(): url = "/items/" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py:94: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_request_files/test_tutorial001.py:127: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_form_no_body ____________________________ def test_post_form_no_body(): > response = client.post("/files/") tests/test_tutorial/test_request_files/test_tutorial001.py:144: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_body_json ______________________________ def test_post_body_json(): > response = client.post("/files/", json={"file": "Foo"}) tests/test_tutorial/test_request_files/test_tutorial001.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_post_file ________________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-0/test_post_file0') def test_post_file(tmpdir): path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"") client = TestClient(app) > response = client.post("/files/", files={"file": open(path, "rb")}) tests/test_tutorial/test_request_files/test_tutorial001.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'158'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_large_file _____________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-0/test_post_large_file0') def test_post_large_file(tmpdir): default_pydantic_max_size = 2 ** 16 path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"x" * (default_pydantic_max_size + 1)) client = TestClient(app) > response = client.post("/files/", files={"file": open(path, "rb")}) tests/test_tutorial/test_request_files/test_tutorial001.py:173: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'65681'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_upload_file _____________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-0/test_post_upload_file0') def test_post_upload_file(tmpdir): path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"") client = TestClient(app) > response = client.post("/uploadfile/", files={"file": open(path, "rb")}) tests/test_tutorial/test_request_files/test_tutorial001.py:184: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/uploadfile/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'158'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_request_files/test_tutorial002.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_form_no_body ____________________________ def test_post_form_no_body(): > response = client.post("/files/") tests/test_tutorial/test_request_files/test_tutorial002.py:164: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_body_json ______________________________ def test_post_body_json(): > response = client.post("/files/", json={"file": "Foo"}) tests/test_tutorial/test_request_files/test_tutorial002.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_post_files ________________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-0/test_post_files0') def test_post_files(tmpdir): path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"") path2 = os.path.join(tmpdir, "test2.txt") with open(path2, "wb") as file: file.write(b"") client = TestClient(app) > response = client.post( "/files/", files=( ("files", ("test.txt", open(path, "rb"))), ("files", ("test2.txt", open(path2, "rb"))), ), ) tests/test_tutorial/test_request_files/test_tutorial002.py:184: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'282'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_upload_file _____________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-0/test_post_upload_file1') def test_post_upload_file(tmpdir): path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"") path2 = os.path.join(tmpdir, "test2.txt") with open(path2, "wb") as file: file.write(b"") client = TestClient(app) > response = client.post( "/uploadfiles/", files=( ("files", ("test.txt", open(path, "rb"))), ("files", ("test2.txt", open(path2, "rb"))), ), ) tests/test_tutorial/test_request_files/test_tutorial002.py:204: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/uploadfiles/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'282'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_root _________________________________ def test_get_root(): client = TestClient(app) > response = client.get("/") tests/test_tutorial/test_request_files/test_tutorial002.py:217: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_request_forms/test_tutorial001.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_post_body_form[/login/-body0-200-expected_response0] ___________ path = '/login/', body = {'password': 'secret', 'username': 'Foo'} expected_status = 200, expected_response = {'username': 'Foo'} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/login/", {"username": "Foo", "password": "secret"}, 200, {"username": "Foo"}, ), ("/login/", {"username": "Foo"}, 422, password_required), ("/login/", {"password": "secret"}, 422, username_required), ("/login/", None, 422, username_and_password_required), ], ) def test_post_body_form(path, body, expected_status, expected_response): > response = client.post(path, data=body) tests/test_tutorial/test_request_forms/test_tutorial001.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'28'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_post_body_form[/login/-body1-422-expected_response1] ___________ path = '/login/', body = {'username': 'Foo'}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'password'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/login/", {"username": "Foo", "password": "secret"}, 200, {"username": "Foo"}, ), ("/login/", {"username": "Foo"}, 422, password_required), ("/login/", {"password": "secret"}, 422, username_required), ("/login/", None, 422, username_and_password_required), ], ) def test_post_body_form(path, body, expected_status, expected_response): > response = client.post(path, data=body) tests/test_tutorial/test_request_forms/test_tutorial001.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'12'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_post_body_form[/login/-body2-422-expected_response2] ___________ path = '/login/', body = {'password': 'secret'}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'username'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/login/", {"username": "Foo", "password": "secret"}, 200, {"username": "Foo"}, ), ("/login/", {"username": "Foo"}, 422, password_required), ("/login/", {"password": "secret"}, 422, username_required), ("/login/", None, 422, username_and_password_required), ], ) def test_post_body_form(path, body, expected_status, expected_response): > response = client.post(path, data=body) tests/test_tutorial/test_request_forms/test_tutorial001.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_post_body_form[/login/-None-422-expected_response3] ___________ path = '/login/', body = None, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'username'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', 'password'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/login/", {"username": "Foo", "password": "secret"}, 200, {"username": "Foo"}, ), ("/login/", {"username": "Foo"}, 422, password_required), ("/login/", {"password": "secret"}, 422, username_required), ("/login/", None, 422, username_and_password_required), ], ) def test_post_body_form(path, body, expected_status, expected_response): > response = client.post(path, data=body) tests/test_tutorial/test_request_forms/test_tutorial001.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_body_json ______________________________ def test_post_body_json(): > response = client.post("/login/", json={"username": "Foo", "password": "secret"}) tests/test_tutorial/test_request_forms/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'41'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:90: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_form_no_body ____________________________ def test_post_form_no_body(): > response = client.post("/files/") tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:149: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_form_no_file ____________________________ def test_post_form_no_file(): > response = client.post("/files/", data={"token": "foo"}) tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:155: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'9'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_body_json ______________________________ def test_post_body_json(): > response = client.post("/files/", json={"file": "Foo", "token": "Bar"}) tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'31'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_post_file_no_token ____________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-0/test_post_file_no_token0') def test_post_file_no_token(tmpdir): path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"") client = TestClient(app) > response = client.post("/files/", files={"file": open(path, "rb")}) tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:172: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'158'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_post_files_and_token ___________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-0/test_post_files_and_token0') def test_post_files_and_token(tmpdir): patha = Path(tmpdir) / "test.txt" pathb = Path(tmpdir) / "testb.txt" patha.write_text("") pathb.write_text("") client = TestClient(app) > response = client.post( "/files/", data={"token": "foo"}, files={ "file": patha.open("rb"), "fileb": ("testb.txt", pathb.open("rb"), "text/plain"), }, ) tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:184: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'397'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.put("/get-or-create-task/foo") tests/test_tutorial/test_response_change_status_code/test_tutorial001.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/get-or-create-task/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.post("/cookie/") tests/test_tutorial/test_response_cookies/test_tutorial001.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/cookie/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.post("/cookie-and-object/") tests/test_tutorial/test_response_cookies/test_tutorial002.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/cookie-and-object/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/headers/") tests/test_tutorial/test_response_headers/test_tutorial001.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/headers/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/headers-and-object/") tests/test_tutorial/test_response_headers/test_tutorial002.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/headers-and-object/' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_response_model/test_tutorial003.py:100: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_post_user ________________________________ def test_post_user(): > response = client.post( "/user/", json={ "username": "foo", "password": "fighter", "email": "foo@example.com", "full_name": "Grave Dohl", }, ) tests/test_tutorial/test_response_model/test_tutorial003.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/user/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'97'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_response_model/test_tutorial004.py:97: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get[/items/foo-data0] __________________________ url = '/items/foo', data = {'name': 'Foo', 'price': 50.2} @pytest.mark.parametrize( "url,data", [ ("/items/foo", {"name": "Foo", "price": 50.2}), ( "/items/bar", {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2}, ), ( "/items/baz", { "name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": [], }, ), ], ) def test_get(url, data): > response = client.get(url) tests/test_tutorial/test_response_model/test_tutorial004.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get[/items/bar-data1] __________________________ url = '/items/bar' data = {'description': 'The bartenders', 'name': 'Bar', 'price': 62, 'tax': 20.2} @pytest.mark.parametrize( "url,data", [ ("/items/foo", {"name": "Foo", "price": 50.2}), ( "/items/bar", {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2}, ), ( "/items/baz", { "name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": [], }, ), ], ) def test_get(url, data): > response = client.get(url) tests/test_tutorial/test_response_model/test_tutorial004.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get[/items/baz-data2] __________________________ url = '/items/baz' data = {'description': None, 'name': 'Baz', 'price': 50.2, 'tags': [], ...} @pytest.mark.parametrize( "url,data", [ ("/items/foo", {"name": "Foo", "price": 50.2}), ( "/items/bar", {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2}, ), ( "/items/baz", { "name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": [], }, ), ], ) def test_get(url, data): > response = client.get(url) tests/test_tutorial/test_response_model/test_tutorial004.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/baz', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_response_model/test_tutorial005.py:124: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_read_item_name ______________________________ def test_read_item_name(): > response = client.get("/items/bar/name") tests/test_tutorial/test_response_model/test_tutorial005.py:130: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar/name', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_read_item_public_data __________________________ def test_read_item_public_data(): > response = client.get("/items/bar/public") tests/test_tutorial/test_response_model/test_tutorial005.py:136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar/public', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_response_model/test_tutorial006.py:124: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_read_item_name ______________________________ def test_read_item_name(): > response = client.get("/items/bar/name") tests/test_tutorial/test_response_model/test_tutorial006.py:130: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar/name', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_read_item_public_data __________________________ def test_read_item_public_data(): > response = client.get("/items/bar/public") tests/test_tutorial/test_response_model/test_tutorial006.py:136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar/public', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_security/test_tutorial001.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_no_token _________________________________ def test_no_token(): > response = client.get("/items") tests/test_tutorial/test_security/test_tutorial001.py:43: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_token __________________________________ def test_token(): > response = client.get("/items", headers={"Authorization": "Bearer testtoken"}) tests/test_tutorial/test_security/test_tutorial001.py:50: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_incorrect_token _____________________________ def test_incorrect_token(): > response = client.get("/items", headers={"Authorization": "Notexistent testtoken"}) tests/test_tutorial/test_security/test_tutorial001.py:56: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Notexistent testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_security/test_tutorial003.py:113: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_login __________________________________ def test_login(): > response = client.post("/token", data={"username": "johndoe", "password": "secret"}) tests/test_tutorial/test_security/test_tutorial003.py:119: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/token', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'32'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_login_incorrect_password _________________________ def test_login_incorrect_password(): > response = client.post( "/token", data={"username": "johndoe", "password": "incorrect"} ) tests/test_tutorial/test_security/test_tutorial003.py:125: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/token', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'35'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_login_incorrect_username _________________________ def test_login_incorrect_username(): > response = client.post("/token", data={"username": "foo", "password": "secret"}) tests/test_tutorial/test_security/test_tutorial003.py:133: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/token', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'28'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_no_token _________________________________ def test_no_token(): > response = client.get("/users/me") tests/test_tutorial/test_security/test_tutorial003.py:139: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_token __________________________________ def test_token(): > response = client.get("/users/me", headers={"Authorization": "Bearer johndoe"}) tests/test_tutorial/test_security/test_tutorial003.py:146: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer johndoe')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_incorrect_token _____________________________ def test_incorrect_token(): > response = client.get("/users/me", headers={"Authorization": "Bearer nonexistent"}) tests/test_tutorial/test_security/test_tutorial003.py:158: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer nonexistent')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_incorrect_token_type ___________________________ def test_incorrect_token_type(): > response = client.get( "/users/me", headers={"Authorization": "Notexistent testtoken"} ) tests/test_tutorial/test_security/test_tutorial003.py:165: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Notexistent testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_inactive_user ______________________________ def test_inactive_user(): > response = client.get("/users/me", headers={"Authorization": "Bearer alice"}) tests/test_tutorial/test_security/test_tutorial003.py:174: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer alice')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_security/test_tutorial006.py:35: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_security_http_basic ___________________________ def test_security_http_basic(): auth = HTTPBasicAuth(username="john", password="secret") > response = client.get("/users/me", auth=auth) tests/test_tutorial/test_security/test_tutorial006.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9objpzZWNyZXQ=')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_basic_no_credentials ____________________ def test_security_http_basic_no_credentials(): > response = client.get("/users/me") tests/test_tutorial/test_security/test_tutorial006.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_security_http_basic_invalid_credentials _________________ def test_security_http_basic_invalid_credentials(): > response = client.get( "/users/me", headers={"Authorization": "Basic notabase64token"} ) tests/test_tutorial/test_security/test_tutorial006.py:55: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic notabase64token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_http_basic_non_basic_credentials ________________ def test_security_http_basic_non_basic_credentials(): payload = b64encode(b"johnsecret").decode("ascii") auth_header = f"Basic {payload}" > response = client.get("/users/me", headers={"Authorization": auth_header}) tests/test_tutorial/test_security/test_tutorial006.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9obnNlY3JldA==')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_setting_override _____________________________ def test_setting_override(): > test_main.test_app() tests/test_tutorial/test_settings/test_app02.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/settings/app02/test_main.py:17: in test_app response = client.get("/info") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/info', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_testing_dbs _______________________________ def test_testing_dbs(): test_db = Path("./test.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app.tests import test_sql_app # Ensure import side effects are re-executed importlib.reload(test_sql_app) > test_sql_app.test_create_user() tests/test_tutorial/test_sql_databases/test_testing_databases.py:14: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/sql_databases/sql_app/tests/test_sql_app.py:33: in test_create_user response = client.post( /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'66'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_openapi_schema_main ___________________________ def test_openapi_schema_main(): > response = client.get("/openapi.json") tests/test_tutorial/test_sub_applications/test_tutorial001.py:47: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_tutorial/test_sub_applications/test_tutorial001.py:53: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_openapi_schema_sub ____________________________ def test_openapi_schema_sub(): > response = client.get("/subapi/openapi.json") tests/test_tutorial/test_sub_applications/test_tutorial001.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/subapi/openapi.json' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_sub ___________________________________ def test_sub(): > response = client.get("/subapi/sub") tests/test_tutorial/test_sub_applications/test_tutorial001.py:65: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/subapi/sub', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): if os.path.isdir("./static"): # pragma: nocover shutil.rmtree("./static") if os.path.isdir("./templates"): # pragma: nocover shutil.rmtree("./templates") shutil.copytree("./docs_src/templates/templates/", "./templates") shutil.copytree("./docs_src/templates/static/", "./static") from docs_src.templates.tutorial001 import app client = TestClient(app) > response = client.get("/items/foo") tests/test_tutorial/test_templates/test_tutorial001.py:17: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_read_main ________________________________ def test_read_main(): > response = client.get("/") docs_src/app_testing/test_main.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_testing/test_main.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > test_read_main() tests/test_tutorial/test_testing/test_main.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/app_testing/test_main.py:9: in test_read_main response = client.get("/") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_read_main ________________________________ def test_read_main(): > response = client.get("/") docs_src/app_testing/tutorial001.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_testing/test_tutorial001.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > test_read_main() tests/test_tutorial/test_testing/test_tutorial001.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/app_testing/tutorial001.py:16: in test_read_main response = client.get("/") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_read_main ________________________________ def test_read_main(): client = TestClient(app) > response = client.get("/") docs_src/app_testing/tutorial002.py:22: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_websocket ________________________________ def test_websocket(): client = TestClient(app) > with client.websocket_connect("/ws") as websocket: docs_src/app_testing/tutorial002.py:29: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError __________________________________ test_main ___________________________________ def test_main(): > test_read_main() tests/test_tutorial/test_testing/test_tutorial002.py:5: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/app_testing/tutorial002.py:22: in test_read_main response = client.get("/") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_ws ____________________________________ def test_ws(): > test_websocket() tests/test_tutorial/test_testing/test_tutorial002.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/app_testing/tutorial002.py:29: in test_websocket with client.websocket_connect("/ws") as websocket: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _______________________________ test_read_items ________________________________ def test_read_items(): > with TestClient(app) as client: docs_src/app_testing/tutorial003.py:21: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError __________________________________ test_main ___________________________________ def test_main(): > test_read_items() tests/test_tutorial/test_testing/test_tutorial003.py:5: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/app_testing/tutorial003.py:21: in test_read_items with TestClient(app) as client: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________________ test_override_in_items ____________________________ def test_override_in_items(): > response = client.get("/items/") docs_src/dependency_testing/tutorial001.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_override_in_items_with_q _________________________ def test_override_in_items_with_q(): > response = client.get("/items/?q=foo") docs_src/dependency_testing/tutorial001.py:43: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_override_in_items_with_params ______________________ def test_override_in_items_with_params(): > response = client.get("/items/?q=foo&skip=100&limit=200") docs_src/dependency_testing/tutorial001.py:52: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_override_in_items_run __________________________ def test_override_in_items_run(): > test_override_in_items() tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:11: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/dependency_testing/tutorial001.py:34: in test_override_in_items response = client.get("/items/") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_override_in_items_with_q_run _______________________ def test_override_in_items_with_q_run(): > test_override_in_items_with_q() tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/dependency_testing/tutorial001.py:43: in test_override_in_items_with_q response = client.get("/items/?q=foo") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_override_in_items_with_params_run ____________________ def test_override_in_items_with_params_run(): > test_override_in_items_with_params() tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:19: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/dependency_testing/tutorial001.py:52: in test_override_in_items_with_params response = client.get("/items/?q=foo&skip=100&limit=200") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_override_in_users ____________________________ def test_override_in_users(): > response = client.get("/users/") tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:23: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_override_in_users_with_q _________________________ def test_override_in_users_with_q(): > response = client.get("/users/?q=foo") tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_override_in_users_with_params ______________________ def test_override_in_users_with_params(): > response = client.get("/users/?q=foo&skip=100&limit=200") tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:41: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_normal_app ________________________________ def test_normal_app(): app.dependency_overrides = None > response = client.get("/items/?q=foo&skip=100&limit=200") tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:51: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/") tests/test_tutorial/test_websockets/test_tutorial001.py:11: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_websocket ________________________________ def test_websocket(): with pytest.raises(WebSocketDisconnect): > with client.websocket_connect("/ws") as websocket: tests/test_tutorial/test_websockets/test_tutorial001.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/") tests/test_tutorial/test_websockets/test_tutorial002.py:11: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_websocket_with_cookie __________________________ def test_websocket_with_cookie(): with pytest.raises(WebSocketDisconnect): > with client.websocket_connect( "/items/foo/ws", cookies={"session": "fakesession"} ) as websocket: tests/test_tutorial/test_websockets/test_tutorial002.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError __________________________ test_websocket_with_header __________________________ def test_websocket_with_header(): with pytest.raises(WebSocketDisconnect): > with client.websocket_connect("/items/bar/ws?token=some-token") as websocket: tests/test_tutorial/test_websockets/test_tutorial002.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _____________________ test_websocket_with_header_and_query _____________________ def test_websocket_with_header_and_query(): with pytest.raises(WebSocketDisconnect): > with client.websocket_connect("/items/2/ws?q=3&token=some-token") as websocket: tests/test_tutorial/test_websockets/test_tutorial002.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError ________________________ test_websocket_no_credentials _________________________ def test_websocket_no_credentials(): > with pytest.raises(WebSocketDisconnect): E Failed: DID NOT RAISE tests/test_tutorial/test_websockets/test_tutorial002.py:74: Failed _________________________ test_websocket_invalid_data __________________________ def test_websocket_invalid_data(): > with pytest.raises(WebSocketDisconnect): E Failed: DID NOT RAISE tests/test_tutorial/test_websockets/test_tutorial002.py:79: Failed _____________________ test_websocket_handle_disconnection ______________________ def test_websocket_handle_disconnection(): > with client.websocket_connect("/ws/1234") as connection, client.websocket_connect( "/ws/5678" ) as connection_two: tests/test_tutorial/test_websockets/test_tutorial003.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError __________________________________ test_flask __________________________________ def test_flask(): > response = client.get("/v1/") tests/test_tutorial/test_wsgi/test_tutorial001.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/v1/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_app ___________________________________ def test_app(): > response = client.get("/v2") tests/test_tutorial/test_wsgi/test_tutorial001.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/v2', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError =========================== short test summary info ============================ FAILED tests/test_additional_properties.py::test_additional_properties_schema FAILED tests/test_additional_properties.py::test_additional_properties_post FAILED tests/test_additional_response_extra.py::test_openapi_schema - Attribu... FAILED tests/test_additional_response_extra.py::test_path_operation - Attribu... FAILED tests/test_additional_responses_bad.py::test_openapi_schema - Attribut... FAILED tests/test_additional_responses_custom_model_in_callback.py::test_openapi_schema FAILED tests/test_additional_responses_custom_validationerror.py::test_openapi_schema FAILED tests/test_additional_responses_default_validationerror.py::test_openapi_schema FAILED tests/test_additional_responses_response_class.py::test_openapi_schema FAILED tests/test_additional_responses_router.py::test_openapi_schema - Attri... FAILED tests/test_additional_responses_router.py::test_a - AttributeError: mo... FAILED tests/test_additional_responses_router.py::test_b - AttributeError: mo... FAILED tests/test_additional_responses_router.py::test_c - AttributeError: mo... FAILED tests/test_application.py::test_get_path[/api_route-200-expected_response0] FAILED tests/test_application.py::test_get_path[/non_decorated_route-200-expected_response1] FAILED tests/test_application.py::test_get_path[/nonexistent-404-expected_response2] FAILED tests/test_application.py::test_get_path[/openapi.json-200-expected_response3] FAILED tests/test_application.py::test_swagger_ui - AttributeError: module 'a... FAILED tests/test_application.py::test_swagger_ui_oauth2_redirect - Attribute... FAILED tests/test_application.py::test_redoc - AttributeError: module 'anyio'... FAILED tests/test_application.py::test_enum_status_code_response - AttributeE... FAILED tests/test_callable_endpoint.py::test_partial - AttributeError: module... FAILED tests/test_custom_route_class.py::test_get_path[/a-200-expected_response0] FAILED tests/test_custom_route_class.py::test_get_path[/a/b-200-expected_response1] FAILED tests/test_custom_route_class.py::test_get_path[/a/b/c-200-expected_response2] FAILED tests/test_custom_route_class.py::test_get_path[/openapi.json-200-expected_response3] FAILED tests/test_custom_swagger_ui_redirect.py::test_swagger_ui - AttributeE... FAILED tests/test_custom_swagger_ui_redirect.py::test_swagger_ui_oauth2_redirect FAILED tests/test_custom_swagger_ui_redirect.py::test_response - AttributeErr... FAILED tests/test_datetime_custom_encoder.py::test_dt - AttributeError: 'Bloc... FAILED tests/test_default_response_class_router.py::test_app - AttributeError... FAILED tests/test_default_response_class_router.py::test_app_override - Attri... FAILED tests/test_default_response_class_router.py::test_router_a - Attribute... FAILED tests/test_default_response_class_router.py::test_router_a_override - ... FAILED tests/test_default_response_class_router.py::test_router_a_a - Attribu... FAILED tests/test_default_response_class_router.py::test_router_a_a_override FAILED tests/test_default_response_class_router.py::test_router_a_b - Attribu... FAILED tests/test_default_response_class_router.py::test_router_a_b_override FAILED tests/test_default_response_class_router.py::test_router_b - Attribute... FAILED tests/test_default_response_class_router.py::test_router_b_override - ... FAILED tests/test_default_response_class_router.py::test_router_b_a - Attribu... FAILED tests/test_default_response_class_router.py::test_router_b_a_override FAILED tests/test_default_response_class_router.py::test_router_b_a_c - Attri... FAILED tests/test_default_response_class_router.py::test_router_b_a_c_override FAILED tests/test_dependency_cache.py::test_normal_counter - AttributeError: ... FAILED tests/test_dependency_cache.py::test_sub_counter - AttributeError: mod... FAILED tests/test_dependency_cache.py::test_sub_counter_no_cache - AttributeE... FAILED tests/test_dependency_class.py::test_class_dependency[/callable-dependency-callable-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/callable-gen-dependency-callable-gen-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/async-callable-dependency-async-callable-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/async-callable-gen-dependency-async-callable-gen-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/synchronous-method-dependency-synchronous-method-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/synchronous-method-gen-dependency-synchronous-method-gen-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/asynchronous-method-dependency-asynchronous-method-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/asynchronous-method-gen-dependency-asynchronous-method-gen-dependency] FAILED tests/test_dependency_contextmanager.py::test_async_state - AttributeE... FAILED tests/test_dependency_contextmanager.py::test_sync_state - AttributeEr... FAILED tests/test_dependency_contextmanager.py::test_async_raise_other - Attr... FAILED tests/test_dependency_contextmanager.py::test_sync_raise_other - Attri... FAILED tests/test_dependency_contextmanager.py::test_async_raise - AttributeE... FAILED tests/test_dependency_contextmanager.py::test_context_b - AttributeErr... FAILED tests/test_dependency_contextmanager.py::test_context_b_raise - Attrib... FAILED tests/test_dependency_contextmanager.py::test_background_tasks - Attri... FAILED tests/test_dependency_contextmanager.py::test_sync_raise - AttributeEr... FAILED tests/test_dependency_contextmanager.py::test_sync_async_state - Attri... FAILED tests/test_dependency_contextmanager.py::test_sync_sync_state - Attrib... FAILED tests/test_dependency_contextmanager.py::test_sync_async_raise_other FAILED tests/test_dependency_contextmanager.py::test_sync_sync_raise_other - ... FAILED tests/test_dependency_contextmanager.py::test_sync_async_raise - Attri... FAILED tests/test_dependency_contextmanager.py::test_sync_sync_raise - Attrib... FAILED tests/test_dependency_contextmanager.py::test_sync_context_b - Attribu... FAILED tests/test_dependency_contextmanager.py::test_sync_context_b_raise - A... FAILED tests/test_dependency_contextmanager.py::test_sync_background_tasks - ... FAILED tests/test_dependency_duplicates.py::test_openapi_schema - AttributeEr... FAILED tests/test_dependency_duplicates.py::test_no_duplicates_invalid - Attr... FAILED tests/test_dependency_duplicates.py::test_no_duplicates - AttributeErr... FAILED tests/test_dependency_duplicates.py::test_duplicates - AttributeError:... FAILED tests/test_dependency_duplicates.py::test_sub_duplicates - AttributeEr... FAILED tests/test_dependency_overrides.py::test_normal_app[/main-depends/-422-expected0] FAILED tests/test_dependency_overrides.py::test_normal_app[/main-depends/?q=foo-200-expected1] FAILED tests/test_dependency_overrides.py::test_normal_app[/main-depends/?q=foo&skip=100&limit=200-200-expected2] FAILED tests/test_dependency_overrides.py::test_normal_app[/decorator-depends/-422-expected3] FAILED tests/test_dependency_overrides.py::test_normal_app[/decorator-depends/?q=foo-200-expected4] FAILED tests/test_dependency_overrides.py::test_normal_app[/decorator-depends/?q=foo&skip=100&limit=200-200-expected5] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-depends/-422-expected6] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-depends/?q=foo-200-expected7] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-depends/?q=foo&skip=100&limit=200-200-expected8] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-decorator-depends/-422-expected9] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-decorator-depends/?q=foo-200-expected10] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-decorator-depends/?q=foo&skip=100&limit=200-200-expected11] FAILED tests/test_dependency_overrides.py::test_override_simple[/main-depends/-200-expected0] FAILED tests/test_dependency_overrides.py::test_override_simple[/main-depends/?q=foo-200-expected1] FAILED tests/test_dependency_overrides.py::test_override_simple[/main-depends/?q=foo&skip=100&limit=200-200-expected2] FAILED tests/test_dependency_overrides.py::test_override_simple[/decorator-depends/-200-expected3] FAILED tests/test_dependency_overrides.py::test_override_simple[/router-depends/-200-expected4] FAILED tests/test_dependency_overrides.py::test_override_simple[/router-depends/?q=foo-200-expected5] FAILED tests/test_dependency_overrides.py::test_override_simple[/router-depends/?q=foo&skip=100&limit=200-200-expected6] FAILED tests/test_dependency_overrides.py::test_override_simple[/router-decorator-depends/-200-expected7] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/main-depends/-422-expected0] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/main-depends/?q=foo-422-expected1] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/main-depends/?k=bar-200-expected2] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/decorator-depends/-422-expected3] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/decorator-depends/?q=foo-422-expected4] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/decorator-depends/?k=bar-200-expected5] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-depends/-422-expected6] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-depends/?q=foo-422-expected7] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-depends/?k=bar-200-expected8] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-decorator-depends/-422-expected9] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-decorator-depends/?q=foo-422-expected10] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-decorator-depends/?k=bar-200-expected11] FAILED tests/test_dependency_security_overrides.py::test_normal - AttributeEr... FAILED tests/test_dependency_security_overrides.py::test_override_data - Attr... FAILED tests/test_dependency_security_overrides.py::test_override_security - ... FAILED tests/test_deprecated_openapi_prefix.py::test_openapi - AttributeError... FAILED tests/test_deprecated_openapi_prefix.py::test_main - AttributeError: m... FAILED tests/test_duplicate_models_openapi.py::test_openapi_schema - Attribut... FAILED tests/test_duplicate_models_openapi.py::test_get_api_route - Attribute... FAILED tests/test_empty_router.py::test_use_empty - AttributeError: 'Blocking... FAILED tests/test_exception_handlers.py::test_override_http_exception - Attri... FAILED tests/test_exception_handlers.py::test_override_request_validation_exception FAILED tests/test_extra_routes.py::test_openapi_schema - AttributeError: modu... FAILED tests/test_extra_routes.py::test_get_api_route - AttributeError: modul... FAILED tests/test_extra_routes.py::test_get_api_route_not_decorated - Attribu... FAILED tests/test_extra_routes.py::test_delete - AttributeError: module 'anyi... FAILED tests/test_extra_routes.py::test_head - AttributeError: module 'anyio'... FAILED tests/test_extra_routes.py::test_options - AttributeError: module 'any... FAILED tests/test_extra_routes.py::test_patch - AttributeError: module 'anyio... FAILED tests/test_extra_routes.py::test_trace - AttributeError: module 'anyio... FAILED tests/test_filter_pydantic_sub_model.py::test_openapi_schema - Attribu... FAILED tests/test_filter_pydantic_sub_model.py::test_filter_sub_model - Attri... FAILED tests/test_filter_pydantic_sub_model.py::test_validator_is_cloned - At... FAILED tests/test_forms_from_non_typing_sequences.py::test_python_list_param_as_form FAILED tests/test_forms_from_non_typing_sequences.py::test_python_set_param_as_form FAILED tests/test_forms_from_non_typing_sequences.py::test_python_tuple_param_as_form FAILED tests/test_get_request_body.py::test_openapi_schema - AttributeError: ... FAILED tests/test_get_request_body.py::test_get_with_body - AttributeError: m... FAILED tests/test_http_connection_injection.py::test_value_extracting_by_http FAILED tests/test_http_connection_injection.py::test_value_extracting_by_ws FAILED tests/test_include_route.py::test_sub_router - AttributeError: module ... FAILED tests/test_include_router_defaults_overrides.py::test_openapi - Attrib... FAILED tests/test_include_router_defaults_overrides.py::test_level1_override FAILED tests/test_include_router_defaults_overrides.py::test_level1_default FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[True-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[True-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[True-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[True-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[False-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[False-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[False-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[False-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-True-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-True-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-True-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-True-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-False-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-False-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-False-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-False-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-True-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-True-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-True-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-True-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-False-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-False-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-False-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-False-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-True-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-True-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-True-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-True-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-False-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-False-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-False-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-False-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-True-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-True-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-True-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-True-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-False-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-False-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-False-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-False-False-False] FAILED tests/test_infer_param_optionality.py::test_get_users - AttributeError... FAILED tests/test_infer_param_optionality.py::test_get_user - AttributeError:... FAILED tests/test_infer_param_optionality.py::test_get_items_1 - AttributeErr... FAILED tests/test_infer_param_optionality.py::test_get_items_2 - AttributeErr... FAILED tests/test_infer_param_optionality.py::test_get_item_1 - AttributeErro... FAILED tests/test_infer_param_optionality.py::test_get_item_2 - AttributeErro... FAILED tests/test_infer_param_optionality.py::test_get_users_items - Attribut... FAILED tests/test_infer_param_optionality.py::test_get_users_item - Attribute... FAILED tests/test_infer_param_optionality.py::test_schema_1 - AttributeError:... FAILED tests/test_infer_param_optionality.py::test_schema_2 - AttributeError:... FAILED tests/test_inherited_custom_class.py::test_dt - AttributeError: 'Block... FAILED tests/test_multi_body_errors.py::test_openapi_schema - AttributeError:... FAILED tests/test_multi_body_errors.py::test_put_correct_body - AttributeErro... FAILED tests/test_multi_body_errors.py::test_jsonable_encoder_requiring_error FAILED tests/test_multi_body_errors.py::test_put_incorrect_body_multiple - At... FAILED tests/test_multi_query_errors.py::test_openapi_schema - AttributeError... FAILED tests/test_multi_query_errors.py::test_multi_query - AttributeError: m... FAILED tests/test_multi_query_errors.py::test_multi_query_incorrect - Attribu... FAILED tests/test_no_swagger_ui_redirect.py::test_swagger_ui - AttributeError... FAILED tests/test_no_swagger_ui_redirect.py::test_swagger_ui_no_oauth2_redirect FAILED tests/test_no_swagger_ui_redirect.py::test_response - AttributeError: ... FAILED tests/test_openapi_servers.py::test_openapi_servers - AttributeError: ... FAILED tests/test_openapi_servers.py::test_app - AttributeError: module 'anyi... FAILED tests/test_param_class.py::test_default_param_query_none - AttributeEr... FAILED tests/test_param_class.py::test_default_param_query - AttributeError: ... FAILED tests/test_param_in_path_and_dependency.py::test_reused_param - Attrib... FAILED tests/test_param_in_path_and_dependency.py::test_read_users - Attribut... FAILED tests/test_path.py::test_text_get - AttributeError: module 'anyio' has... FAILED tests/test_path.py::test_nonexistent - AttributeError: module 'anyio' ... FAILED tests/test_path.py::test_get_path[/path/foobar-200-foobar] - Attribute... FAILED tests/test_path.py::test_get_path[/path/str/foobar-200-foobar] - Attri... FAILED tests/test_path.py::test_get_path[/path/str/42-200-42] - AttributeErro... FAILED tests/test_path.py::test_get_path[/path/str/True-200-True] - Attribute... FAILED tests/test_path.py::test_get_path[/path/int/foobar-422-expected_response4] FAILED tests/test_path.py::test_get_path[/path/int/True-422-expected_response5] FAILED tests/test_path.py::test_get_path[/path/int/42-200-42] - AttributeErro... FAILED tests/test_path.py::test_get_path[/path/int/42.5-422-expected_response7] FAILED tests/test_path.py::test_get_path[/path/float/foobar-422-expected_response8] FAILED tests/test_path.py::test_get_path[/path/float/True-422-expected_response9] FAILED tests/test_path.py::test_get_path[/path/float/42-200-42] - AttributeEr... FAILED tests/test_path.py::test_get_path[/path/float/42.5-200-42.5] - Attribu... FAILED tests/test_path.py::test_get_path[/path/bool/foobar-422-expected_response12] FAILED tests/test_path.py::test_get_path[/path/bool/True-200-True] - Attribut... FAILED tests/test_path.py::test_get_path[/path/bool/42-422-expected_response14] FAILED tests/test_path.py::test_get_path[/path/bool/42.5-422-expected_response15] FAILED tests/test_path.py::test_get_path[/path/bool/1-200-True] - AttributeEr... FAILED tests/test_path.py::test_get_path[/path/bool/0-200-False] - AttributeE... FAILED tests/test_path.py::test_get_path[/path/bool/true-200-True] - Attribut... FAILED tests/test_path.py::test_get_path[/path/bool/False-200-False] - Attrib... FAILED tests/test_path.py::test_get_path[/path/bool/false-200-False] - Attrib... FAILED tests/test_path.py::test_get_path[/path/param/foo-200-foo] - Attribute... FAILED tests/test_path.py::test_get_path[/path/param-required/foo-200-foo] - ... FAILED tests/test_path.py::test_get_path[/path/param-minlength/foo-200-foo] FAILED tests/test_path.py::test_get_path[/path/param-minlength/fo-422-expected_response24] FAILED tests/test_path.py::test_get_path[/path/param-maxlength/foo-200-foo] FAILED tests/test_path.py::test_get_path[/path/param-maxlength/foobar-422-expected_response26] FAILED tests/test_path.py::test_get_path[/path/param-min_maxlength/foo-200-foo] FAILED tests/test_path.py::test_get_path[/path/param-min_maxlength/foobar-422-expected_response28] FAILED tests/test_path.py::test_get_path[/path/param-min_maxlength/f-422-expected_response29] FAILED tests/test_path.py::test_get_path[/path/param-gt/42-200-42] - Attribut... FAILED tests/test_path.py::test_get_path[/path/param-gt/2-422-expected_response31] FAILED tests/test_path.py::test_get_path[/path/param-gt0/0.05-200-0.05] - Att... FAILED tests/test_path.py::test_get_path[/path/param-gt0/0-422-expected_response33] FAILED tests/test_path.py::test_get_path[/path/param-ge/42-200-42] - Attribut... FAILED tests/test_path.py::test_get_path[/path/param-ge/3-200-3] - AttributeE... FAILED tests/test_path.py::test_get_path[/path/param-ge/2-422-expected_response36] FAILED tests/test_path.py::test_get_path[/path/param-lt/42-422-expected_response37] FAILED tests/test_path.py::test_get_path[/path/param-lt/2-200-2] - AttributeE... FAILED tests/test_path.py::test_get_path[/path/param-lt0/-1-200--1] - Attribu... FAILED tests/test_path.py::test_get_path[/path/param-lt0/0-422-expected_response40] FAILED tests/test_path.py::test_get_path[/path/param-le/42-422-expected_response41] FAILED tests/test_path.py::test_get_path[/path/param-le/3-200-3] - AttributeE... FAILED tests/test_path.py::test_get_path[/path/param-le/2-200-2] - AttributeE... FAILED tests/test_path.py::test_get_path[/path/param-lt-gt/2-200-2] - Attribu... FAILED tests/test_path.py::test_get_path[/path/param-lt-gt/4-422-expected_response45] FAILED tests/test_path.py::test_get_path[/path/param-lt-gt/0-422-expected_response46] FAILED tests/test_path.py::test_get_path[/path/param-le-ge/2-200-2] - Attribu... FAILED tests/test_path.py::test_get_path[/path/param-le-ge/1-200-1] - Attribu... FAILED tests/test_path.py::test_get_path[/path/param-le-ge/3-200-3] - Attribu... FAILED tests/test_path.py::test_get_path[/path/param-le-ge/4-422-expected_response50] FAILED tests/test_path.py::test_get_path[/path/param-lt-int/2-200-2] - Attrib... FAILED tests/test_path.py::test_get_path[/path/param-lt-int/42-422-expected_response52] FAILED tests/test_path.py::test_get_path[/path/param-lt-int/2.7-422-expected_response53] FAILED tests/test_path.py::test_get_path[/path/param-gt-int/42-200-42] - Attr... FAILED tests/test_path.py::test_get_path[/path/param-gt-int/2-422-expected_response55] FAILED tests/test_path.py::test_get_path[/path/param-gt-int/2.7-422-expected_response56] FAILED tests/test_path.py::test_get_path[/path/param-le-int/42-422-expected_response57] FAILED tests/test_path.py::test_get_path[/path/param-le-int/3-200-3] - Attrib... FAILED tests/test_path.py::test_get_path[/path/param-le-int/2-200-2] - Attrib... FAILED tests/test_path.py::test_get_path[/path/param-le-int/2.7-422-expected_response60] FAILED tests/test_path.py::test_get_path[/path/param-ge-int/42-200-42] - Attr... FAILED tests/test_path.py::test_get_path[/path/param-ge-int/3-200-3] - Attrib... FAILED tests/test_path.py::test_get_path[/path/param-ge-int/2-422-expected_response63] FAILED tests/test_path.py::test_get_path[/path/param-ge-int/2.7-422-expected_response64] FAILED tests/test_path.py::test_get_path[/path/param-lt-gt-int/2-200-2] - Att... FAILED tests/test_path.py::test_get_path[/path/param-lt-gt-int/4-422-expected_response66] FAILED tests/test_path.py::test_get_path[/path/param-lt-gt-int/0-422-expected_response67] FAILED tests/test_path.py::test_get_path[/path/param-lt-gt-int/2.7-422-expected_response68] FAILED tests/test_path.py::test_get_path[/path/param-le-ge-int/2-200-2] - Att... FAILED tests/test_path.py::test_get_path[/path/param-le-ge-int/1-200-1] - Att... FAILED tests/test_path.py::test_get_path[/path/param-le-ge-int/3-200-3] - Att... FAILED tests/test_path.py::test_get_path[/path/param-le-ge-int/4-422-expected_response72] FAILED tests/test_path.py::test_get_path[/path/param-le-ge-int/2.7-422-expected_response73] FAILED tests/test_put_no_body.py::test_openapi_schema - AttributeError: modul... FAILED tests/test_put_no_body.py::test_put_no_body - AttributeError: module '... FAILED tests/test_put_no_body.py::test_put_no_body_with_body - AttributeError... FAILED tests/test_query.py::test_get_path[/query-422-expected_response0] - At... FAILED tests/test_query.py::test_get_path[/query?query=baz-200-foo bar baz] FAILED tests/test_query.py::test_get_path[/query?not_declared=baz-422-expected_response2] FAILED tests/test_query.py::test_get_path[/query/optional-200-foo bar] - Attr... FAILED tests/test_query.py::test_get_path[/query/optional?query=baz-200-foo bar baz] FAILED tests/test_query.py::test_get_path[/query/optional?not_declared=baz-200-foo bar] FAILED tests/test_query.py::test_get_path[/query/int-422-expected_response6] FAILED tests/test_query.py::test_get_path[/query/int?query=42-200-foo bar 42] FAILED tests/test_query.py::test_get_path[/query/int?query=42.5-422-expected_response8] FAILED tests/test_query.py::test_get_path[/query/int?query=baz-422-expected_response9] FAILED tests/test_query.py::test_get_path[/query/int?not_declared=baz-422-expected_response10] FAILED tests/test_query.py::test_get_path[/query/int/optional-200-foo bar] - ... FAILED tests/test_query.py::test_get_path[/query/int/optional?query=50-200-foo bar 50] FAILED tests/test_query.py::test_get_path[/query/int/optional?query=foo-422-expected_response13] FAILED tests/test_query.py::test_get_path[/query/int/default-200-foo bar 10] FAILED tests/test_query.py::test_get_path[/query/int/default?query=50-200-foo bar 50] FAILED tests/test_query.py::test_get_path[/query/int/default?query=foo-422-expected_response16] FAILED tests/test_query.py::test_get_path[/query/param-200-foo bar] - Attribu... FAILED tests/test_query.py::test_get_path[/query/param?query=50-200-foo bar 50] FAILED tests/test_query.py::test_get_path[/query/param-required-422-expected_response19] FAILED tests/test_query.py::test_get_path[/query/param-required?query=50-200-foo bar 50] FAILED tests/test_query.py::test_get_path[/query/param-required/int-422-expected_response21] FAILED tests/test_query.py::test_get_path[/query/param-required/int?query=50-200-foo bar 50] FAILED tests/test_query.py::test_get_path[/query/param-required/int?query=foo-422-expected_response23] FAILED tests/test_repeated_cookie_headers.py::test_cookie_is_set_once - Attri... FAILED tests/test_repeated_dependency_schema.py::test_schema - AttributeError... FAILED tests/test_repeated_dependency_schema.py::test_response - AttributeErr... FAILED tests/test_request_body_parameters_media_type.py::test_openapi_schema FAILED tests/test_response_change_status_code.py::test_dependency_set_status_code FAILED tests/test_response_class_no_mediatype.py::test_openapi_schema - Attri... FAILED tests/test_response_code_no_body.py::test_openapi_schema - AttributeEr... FAILED tests/test_response_model_sub_types.py::test_openapi_schema - Attribut... FAILED tests/test_response_model_sub_types.py::test_path_operations - Attribu... FAILED tests/test_router_events.py::test_router_events - AttributeError: 'Blo... FAILED tests/test_router_prefix_with_template.py::test_get - AttributeError: ... FAILED tests/test_security_api_key_cookie.py::test_openapi_schema - Attribute... FAILED tests/test_security_api_key_cookie.py::test_security_api_key - Attribu... FAILED tests/test_security_api_key_cookie.py::test_security_api_key_no_key - ... FAILED tests/test_security_api_key_cookie_optional.py::test_openapi_schema - ... FAILED tests/test_security_api_key_cookie_optional.py::test_security_api_key FAILED tests/test_security_api_key_cookie_optional.py::test_security_api_key_no_key FAILED tests/test_security_api_key_header.py::test_openapi_schema - Attribute... FAILED tests/test_security_api_key_header.py::test_security_api_key - Attribu... FAILED tests/test_security_api_key_header.py::test_security_api_key_no_key - ... FAILED tests/test_security_api_key_header_optional.py::test_openapi_schema - ... FAILED tests/test_security_api_key_header_optional.py::test_security_api_key FAILED tests/test_security_api_key_header_optional.py::test_security_api_key_no_key FAILED tests/test_security_api_key_query.py::test_openapi_schema - AttributeE... FAILED tests/test_security_api_key_query.py::test_security_api_key - Attribut... FAILED tests/test_security_api_key_query.py::test_security_api_key_no_key - A... FAILED tests/test_security_api_key_query_optional.py::test_openapi_schema - A... FAILED tests/test_security_api_key_query_optional.py::test_security_api_key FAILED tests/test_security_api_key_query_optional.py::test_security_api_key_no_key FAILED tests/test_security_http_base.py::test_openapi_schema - AttributeError... FAILED tests/test_security_http_base.py::test_security_http_base - AttributeE... FAILED tests/test_security_http_base.py::test_security_http_base_no_credentials FAILED tests/test_security_http_base_optional.py::test_openapi_schema - Attri... FAILED tests/test_security_http_base_optional.py::test_security_http_base - A... FAILED tests/test_security_http_base_optional.py::test_security_http_base_no_credentials FAILED tests/test_security_http_basic_optional.py::test_openapi_schema - Attr... FAILED tests/test_security_http_basic_optional.py::test_security_http_basic FAILED tests/test_security_http_basic_optional.py::test_security_http_basic_no_credentials FAILED tests/test_security_http_basic_optional.py::test_security_http_basic_invalid_credentials FAILED tests/test_security_http_basic_optional.py::test_security_http_basic_non_basic_credentials FAILED tests/test_security_http_basic_realm.py::test_openapi_schema - Attribu... FAILED tests/test_security_http_basic_realm.py::test_security_http_basic - At... FAILED tests/test_security_http_basic_realm.py::test_security_http_basic_no_credentials FAILED tests/test_security_http_basic_realm.py::test_security_http_basic_invalid_credentials FAILED tests/test_security_http_basic_realm.py::test_security_http_basic_non_basic_credentials FAILED tests/test_security_http_bearer.py::test_openapi_schema - AttributeErr... FAILED tests/test_security_http_bearer.py::test_security_http_bearer - Attrib... FAILED tests/test_security_http_bearer.py::test_security_http_bearer_no_credentials FAILED tests/test_security_http_bearer.py::test_security_http_bearer_incorrect_scheme_credentials FAILED tests/test_security_http_bearer_optional.py::test_openapi_schema - Att... FAILED tests/test_security_http_bearer_optional.py::test_security_http_bearer FAILED tests/test_security_http_bearer_optional.py::test_security_http_bearer_no_credentials FAILED tests/test_security_http_bearer_optional.py::test_security_http_bearer_incorrect_scheme_credentials FAILED tests/test_security_http_digest.py::test_openapi_schema - AttributeErr... FAILED tests/test_security_http_digest.py::test_security_http_digest - Attrib... FAILED tests/test_security_http_digest.py::test_security_http_digest_no_credentials FAILED tests/test_security_http_digest.py::test_security_http_digest_incorrect_scheme_credentials FAILED tests/test_security_http_digest_optional.py::test_openapi_schema - Att... FAILED tests/test_security_http_digest_optional.py::test_security_http_digest FAILED tests/test_security_http_digest_optional.py::test_security_http_digest_no_credentials FAILED tests/test_security_http_digest_optional.py::test_security_http_digest_incorrect_scheme_credentials FAILED tests/test_security_oauth2.py::test_openapi_schema - AttributeError: m... FAILED tests/test_security_oauth2.py::test_security_oauth2 - AttributeError: ... FAILED tests/test_security_oauth2.py::test_security_oauth2_password_other_header FAILED tests/test_security_oauth2.py::test_security_oauth2_password_bearer_no_header FAILED tests/test_security_oauth2.py::test_strict_login[None-422-expected_response0] FAILED tests/test_security_oauth2.py::test_strict_login[data1-422-expected_response1] FAILED tests/test_security_oauth2.py::test_strict_login[data2-422-expected_response2] FAILED tests/test_security_oauth2.py::test_strict_login[data3-200-expected_response3] FAILED tests/test_security_oauth2_authorization_code_bearer.py::test_openapi_schema FAILED tests/test_security_oauth2_authorization_code_bearer.py::test_no_token FAILED tests/test_security_oauth2_authorization_code_bearer.py::test_incorrect_token FAILED tests/test_security_oauth2_authorization_code_bearer.py::test_token - ... FAILED tests/test_security_oauth2_optional.py::test_openapi_schema - Attribut... FAILED tests/test_security_oauth2_optional.py::test_security_oauth2 - Attribu... FAILED tests/test_security_oauth2_optional.py::test_security_oauth2_password_other_header FAILED tests/test_security_oauth2_optional.py::test_security_oauth2_password_bearer_no_header FAILED tests/test_security_oauth2_optional.py::test_strict_login[None-422-expected_response0] FAILED tests/test_security_oauth2_optional.py::test_strict_login[data1-422-expected_response1] FAILED tests/test_security_oauth2_optional.py::test_strict_login[data2-422-expected_response2] FAILED tests/test_security_oauth2_optional.py::test_strict_login[data3-200-expected_response3] FAILED tests/test_security_oauth2_password_bearer_optional.py::test_openapi_schema FAILED tests/test_security_oauth2_password_bearer_optional.py::test_no_token FAILED tests/test_security_oauth2_password_bearer_optional.py::test_token - A... FAILED tests/test_security_oauth2_password_bearer_optional.py::test_incorrect_token FAILED tests/test_security_openid_connect.py::test_openapi_schema - Attribute... FAILED tests/test_security_openid_connect.py::test_security_oauth2 - Attribut... FAILED tests/test_security_openid_connect.py::test_security_oauth2_password_other_header FAILED tests/test_security_openid_connect.py::test_security_oauth2_password_bearer_no_header FAILED tests/test_security_openid_connect_optional.py::test_openapi_schema - ... FAILED tests/test_security_openid_connect_optional.py::test_security_oauth2 FAILED tests/test_security_openid_connect_optional.py::test_security_oauth2_password_other_header FAILED tests/test_security_openid_connect_optional.py::test_security_oauth2_password_bearer_no_header FAILED tests/test_serialize_response.py::test_valid - AttributeError: module ... FAILED tests/test_serialize_response.py::test_coerce - AttributeError: module... FAILED tests/test_serialize_response.py::test_validlist - AttributeError: mod... FAILED tests/test_serialize_response_dataclass.py::test_valid - AttributeErro... FAILED tests/test_serialize_response_dataclass.py::test_coerce - AttributeErr... FAILED tests/test_serialize_response_dataclass.py::test_validlist - Attribute... FAILED tests/test_serialize_response_model.py::test_valid - AttributeError: m... FAILED tests/test_serialize_response_model.py::test_coerce - AttributeError: ... FAILED tests/test_serialize_response_model.py::test_validlist - AttributeErro... FAILED tests/test_serialize_response_model.py::test_validdict - AttributeErro... FAILED tests/test_serialize_response_model.py::test_valid_exclude_unset - Att... FAILED tests/test_serialize_response_model.py::test_coerce_exclude_unset - At... FAILED tests/test_serialize_response_model.py::test_validlist_exclude_unset FAILED tests/test_serialize_response_model.py::test_validdict_exclude_unset FAILED tests/test_skip_defaults.py::test_return_defaults - AttributeError: mo... FAILED tests/test_skip_defaults.py::test_return_exclude_unset - AttributeErro... FAILED tests/test_skip_defaults.py::test_return_exclude_defaults - AttributeE... FAILED tests/test_skip_defaults.py::test_return_exclude_none - AttributeError... FAILED tests/test_skip_defaults.py::test_return_exclude_unset_none - Attribut... FAILED tests/test_starlette_exception.py::test_openapi_schema - AttributeErro... FAILED tests/test_starlette_exception.py::test_get_item - AttributeError: mod... FAILED tests/test_starlette_exception.py::test_get_item_not_found - Attribute... FAILED tests/test_starlette_exception.py::test_get_starlette_item - Attribute... FAILED tests/test_starlette_exception.py::test_get_starlette_item_not_found FAILED tests/test_starlette_urlconvertors.py::test_route_converters_int - Att... FAILED tests/test_starlette_urlconvertors.py::test_route_converters_float - A... FAILED tests/test_starlette_urlconvertors.py::test_route_converters_path - At... FAILED tests/test_sub_callbacks.py::test_openapi - AttributeError: 'BlockingP... FAILED tests/test_sub_callbacks.py::test_get - AttributeError: module 'anyio'... FAILED tests/test_swagger_ui_init_oauth.py::test_swagger_ui - AttributeError:... FAILED tests/test_swagger_ui_init_oauth.py::test_response - AttributeError: m... FAILED tests/test_union_body.py::test_item_openapi_schema - AttributeError: m... FAILED tests/test_union_body.py::test_post_other_item - AttributeError: modul... FAILED tests/test_union_body.py::test_post_item - AttributeError: module 'any... FAILED tests/test_union_inherited_body.py::test_inherited_item_openapi_schema FAILED tests/test_union_inherited_body.py::test_post_extended_item - Attribut... FAILED tests/test_union_inherited_body.py::test_post_item - AttributeError: m... FAILED tests/test_validate_response.py::test_invalid - AttributeError: module... FAILED tests/test_validate_response.py::test_double_invalid - AttributeError:... FAILED tests/test_validate_response.py::test_invalid_list - AttributeError: m... FAILED tests/test_validate_response_dataclass.py::test_invalid - AttributeErr... FAILED tests/test_validate_response_dataclass.py::test_double_invalid - Attri... FAILED tests/test_validate_response_dataclass.py::test_invalid_list - Attribu... FAILED tests/test_validate_response_recursive.py::test_recursive - AttributeE... FAILED tests/test_ws_router.py::test_app - AttributeError: 'BlockingPortal' o... FAILED tests/test_ws_router.py::test_router - AttributeError: 'BlockingPortal... FAILED tests/test_ws_router.py::test_prefix_router - AttributeError: 'Blockin... FAILED tests/test_ws_router.py::test_router2 - AttributeError: 'BlockingPorta... FAILED tests/test_ws_router.py::test_router_ws_depends - AttributeError: 'Blo... FAILED tests/test_ws_router.py::test_router_ws_depends_with_override - Attrib... FAILED tests/test_modules_same_name_body/test_main.py::test_openapi_schema - ... FAILED tests/test_modules_same_name_body/test_main.py::test_post_a - Attribut... FAILED tests/test_modules_same_name_body/test_main.py::test_post_a_invalid - ... FAILED tests/test_modules_same_name_body/test_main.py::test_post_b - Attribut... FAILED tests/test_modules_same_name_body/test_main.py::test_post_b_invalid - ... FAILED tests/test_tutorial/test_additional_responses/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_additional_responses/test_tutorial001.py::test_path_operation FAILED tests/test_tutorial/test_additional_responses/test_tutorial001.py::test_path_operation_not_found FAILED tests/test_tutorial/test_additional_responses/test_tutorial002.py::test_openapi_schema FAILED tests/test_tutorial/test_additional_responses/test_tutorial002.py::test_path_operation FAILED tests/test_tutorial/test_additional_responses/test_tutorial002.py::test_path_operation_img FAILED tests/test_tutorial/test_additional_responses/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_additional_responses/test_tutorial003.py::test_path_operation FAILED tests/test_tutorial/test_additional_responses/test_tutorial003.py::test_path_operation_not_found FAILED tests/test_tutorial/test_additional_responses/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_additional_responses/test_tutorial004.py::test_path_operation FAILED tests/test_tutorial/test_additional_responses/test_tutorial004.py::test_path_operation_img FAILED tests/test_tutorial/test_additional_status_codes/test_tutorial001.py::test_update FAILED tests/test_tutorial/test_additional_status_codes/test_tutorial001.py::test_create FAILED tests/test_tutorial/test_advanced_middleware/test_tutorial001.py::test_middleware FAILED tests/test_tutorial/test_advanced_middleware/test_tutorial002.py::test_middleware FAILED tests/test_tutorial/test_advanced_middleware/test_tutorial003.py::test_middleware FAILED tests/test_tutorial/test_async_sql_databases/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_async_sql_databases/test_tutorial001.py::test_create_read FAILED tests/test_tutorial/test_async_tests/test_main.py::test_root - Attribu... FAILED tests/test_tutorial/test_async_tests/test_main.py::test_async_testing FAILED tests/test_tutorial/test_background_tasks/test_tutorial001.py::test - ... FAILED tests/test_tutorial/test_background_tasks/test_tutorial002.py::test - ... FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py::test_openapi FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py::test_main FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py::test_openapi FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py::test_main FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py::test_openapi FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py::test_main FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial004.py::test_openapi FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial004.py::test_main FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users?token=jessica-200-expected_response0-headers0] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users-422-expected_response1-headers1] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users/foo?token=jessica-200-expected_response2-headers2] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users/foo-422-expected_response3-headers3] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users/me?token=jessica-200-expected_response4-headers4] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users/me-422-expected_response5-headers5] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items?token=jessica-200-expected_response6-headers6] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items-422-expected_response7-headers7] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items/plumbus?token=jessica-200-expected_response8-headers8] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items/plumbus-422-expected_response9-headers9] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items?token=jessica-400-expected_response10-headers10] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items/bar?token=jessica-400-expected_response11-headers11] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items?token=jessica-422-expected_response12-headers12] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items/plumbus?token=jessica-422-expected_response13-headers13] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/?token=jessica-200-expected_response14-headers14] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/-422-expected_response15-headers15] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/openapi.json-200-expected_response16-headers16] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_put_no_header FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_put_invalid_header FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_put - ... FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_put_forbidden FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_admin FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_admin_invalid_header FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body0-200-expected_response0] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body1-200-expected_response1] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body2-200-expected_response2] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body3-200-expected_response3] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body4-422-expected_response4] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body5-422-expected_response5] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body6-422-expected_response6] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-None-422-expected_response7] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_broken_body FAILED tests/test_tutorial/test_body_fields/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_body_fields/test_tutorial001.py::test[/items/5-body0-200-expected_response0] FAILED tests/test_tutorial/test_body_fields/test_tutorial001.py::test[/items/6-body1-200-expected_response1] FAILED tests/test_tutorial/test_body_fields/test_tutorial001.py::test[/items/5-body2-422-expected_response2] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial001.py::test_post_body[/items/5?q=bar-body0-200-expected_response0] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial001.py::test_post_body[/items/5?q=bar-None-200-expected_response1] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial001.py::test_post_body[/items/5-None-200-expected_response2] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial001.py::test_post_body[/items/foo-None-422-expected_response3] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial003.py::test_post_body[/items/5-body0-200-expected_response0] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial003.py::test_post_body[/items/5-None-422-expected_response1] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial003.py::test_post_body[/items/5-body2-422-expected_response2] FAILED tests/test_tutorial/test_body_nested_models/test_tutorial009.py::test_openapi_schema FAILED tests/test_tutorial/test_body_nested_models/test_tutorial009.py::test_post_body FAILED tests/test_tutorial/test_body_nested_models/test_tutorial009.py::test_post_invalid_body FAILED tests/test_tutorial/test_body_updates/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_body_updates/test_tutorial001.py::test_get - ... FAILED tests/test_tutorial/test_body_updates/test_tutorial001.py::test_put - ... FAILED tests/test_tutorial/test_conditional_openapi/test_tutorial001.py::test_default_openapi FAILED tests/test_tutorial/test_conditional_openapi/test_tutorial001.py::test_disable_openapi FAILED tests/test_tutorial/test_cookie_params/test_tutorial001.py::test[/openapi.json-None-200-expected_response0] FAILED tests/test_tutorial/test_cookie_params/test_tutorial001.py::test[/items-None-200-expected_response1] FAILED tests/test_tutorial/test_cookie_params/test_tutorial001.py::test[/items-cookies2-200-expected_response2] FAILED tests/test_tutorial/test_cookie_params/test_tutorial001.py::test[/items-cookies3-200-expected_response3] FAILED tests/test_tutorial/test_cookie_params/test_tutorial001.py::test[/items-cookies4-200-expected_response4] FAILED tests/test_tutorial/test_cors/test_tutorial001.py::test_cors - Attribu... FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py::test_gzip_request[True] FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py::test_gzip_request[False] FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py::test_request_class FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py::test_endpoint_works FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py::test_exception_handler_body_access FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py::test_get FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py::test_get_timed FAILED tests/test_tutorial/test_custom_response/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_custom_response/test_tutorial001b.py::test_openapi_schema FAILED tests/test_tutorial/test_custom_response/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_custom_response/test_tutorial005.py::test_openapi_schema FAILED tests/test_tutorial/test_custom_response/test_tutorial005.py::test_get FAILED tests/test_tutorial/test_custom_response/test_tutorial006.py::test_get FAILED tests/test_tutorial/test_custom_response/test_tutorial007.py::test_get FAILED tests/test_tutorial/test_custom_response/test_tutorial008.py::test_get FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/items-200-expected_response0] FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/items?q=foo-200-expected_response1] FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/items?q=foo&skip=5-200-expected_response2] FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/items?q=foo&skip=5&limit=30-200-expected_response3] FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/users-200-expected_response4] FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/openapi.json-200-expected_response5] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items-200-expected_response0] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items?q=foo-200-expected_response1] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items?q=foo&skip=1-200-expected_response2] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items?q=bar&limit=2-200-expected_response3] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items?q=bar&skip=1&limit=1-200-expected_response4] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items?limit=1&q=bar&skip=1-200-expected_response5] FAILED tests/test_tutorial/test_dependencies/test_tutorial006.py::test_openapi_schema FAILED tests/test_tutorial/test_dependencies/test_tutorial006.py::test_get_no_headers FAILED tests/test_tutorial/test_dependencies/test_tutorial006.py::test_get_invalid_one_header FAILED tests/test_tutorial/test_dependencies/test_tutorial006.py::test_get_invalid_second_header FAILED tests/test_tutorial/test_dependencies/test_tutorial006.py::test_get_valid_headers FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_openapi_schema FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_no_headers_items FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_no_headers_users FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_invalid_one_header_items FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_invalid_one_users FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_invalid_second_header_items FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_invalid_second_header_users FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_valid_headers_items FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_valid_headers_users FAILED tests/test_tutorial/test_events/test_tutorial001.py::test_events - Att... FAILED tests/test_tutorial/test_events/test_tutorial002.py::test_events - Att... FAILED tests/test_tutorial/test_extending_openapi/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_extending_openapi/test_tutorial001.py::test FAILED tests/test_tutorial/test_extra_data_types/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_extra_data_types/test_tutorial001.py::test_extra_types FAILED tests/test_tutorial/test_extra_models/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_extra_models/test_tutorial003.py::test_get_car FAILED tests/test_tutorial/test_extra_models/test_tutorial003.py::test_get_plane FAILED tests/test_tutorial/test_extra_models/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_extra_models/test_tutorial004.py::test_get_items FAILED tests/test_tutorial/test_extra_models/test_tutorial005.py::test_openapi_schema FAILED tests/test_tutorial/test_extra_models/test_tutorial005.py::test_get_items FAILED tests/test_tutorial/test_first_steps/test_tutorial001.py::test_get_path[/-200-expected_response0] FAILED tests/test_tutorial/test_first_steps/test_tutorial001.py::test_get_path[/nonexistent-404-expected_response1] FAILED tests/test_tutorial/test_first_steps/test_tutorial001.py::test_get_path[/openapi.json-200-expected_response2] FAILED tests/test_tutorial/test_handling_errors/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial001.py::test_get_item FAILED tests/test_tutorial/test_handling_errors/test_tutorial001.py::test_get_item_not_found FAILED tests/test_tutorial/test_handling_errors/test_tutorial002.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial002.py::test_get_item_header FAILED tests/test_tutorial/test_handling_errors/test_tutorial002.py::test_get_item_not_found_header FAILED tests/test_tutorial/test_handling_errors/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial003.py::test_get FAILED tests/test_tutorial/test_handling_errors/test_tutorial003.py::test_get_exception FAILED tests/test_tutorial/test_handling_errors/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial004.py::test_get_validation_error FAILED tests/test_tutorial/test_handling_errors/test_tutorial004.py::test_get_http_error FAILED tests/test_tutorial/test_handling_errors/test_tutorial004.py::test_get FAILED tests/test_tutorial/test_handling_errors/test_tutorial005.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial005.py::test_post_validation_error FAILED tests/test_tutorial/test_handling_errors/test_tutorial005.py::test_post FAILED tests/test_tutorial/test_handling_errors/test_tutorial006.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial006.py::test_get_validation_error FAILED tests/test_tutorial/test_handling_errors/test_tutorial006.py::test_get_http_error FAILED tests/test_tutorial/test_handling_errors/test_tutorial006.py::test_get FAILED tests/test_tutorial/test_header_params/test_tutorial001.py::test[/openapi.json-None-200-expected_response0] FAILED tests/test_tutorial/test_header_params/test_tutorial001.py::test[/items-None-200-expected_response1] FAILED tests/test_tutorial/test_header_params/test_tutorial001.py::test[/items-headers2-200-expected_response2] FAILED tests/test_tutorial/test_header_params/test_tutorial001.py::test[/items-headers3-200-expected_response3] FAILED tests/test_tutorial/test_metadata/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_metadata/test_tutorial001.py::test_items - At... FAILED tests/test_tutorial/test_metadata/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_metadata/test_tutorial004.py::test_path_operations FAILED tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py::test_openapi FAILED tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py::test_get FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial001.py::test_get FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial002.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial002.py::test_get FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial003.py::test_get FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py::test_query_params_str_validations FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py::test_query_params_str_validations FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py::test_query_params_str_validations[/items/-200-expected_response0] FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py::test_query_params_str_validations[/users/-200-expected_response1] FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py::test_query_params_str_validations[/elements/-200-expected_response2] FAILED tests/test_tutorial/test_path_params/test_tutorial004.py::test_openapi FAILED tests/test_tutorial/test_path_params/test_tutorial004.py::test_file_path FAILED tests/test_tutorial/test_path_params/test_tutorial004.py::test_root_file_path FAILED tests/test_tutorial/test_path_params/test_tutorial005.py::test_openapi FAILED tests/test_tutorial/test_path_params/test_tutorial005.py::test_get_enums[/models/alexnet-200-expected0] FAILED tests/test_tutorial/test_path_params/test_tutorial005.py::test_get_enums[/models/lenet-200-expected1] FAILED tests/test_tutorial/test_path_params/test_tutorial005.py::test_get_enums[/models/resnet-200-expected2] FAILED tests/test_tutorial/test_path_params/test_tutorial005.py::test_get_enums[/models/foo-422-expected3] FAILED tests/test_tutorial/test_query_params/test_tutorial005.py::test[/openapi.json-200-expected_response0] FAILED tests/test_tutorial/test_query_params/test_tutorial005.py::test[/items/foo?needy=very-200-expected_response1] FAILED tests/test_tutorial/test_query_params/test_tutorial005.py::test[/items/foo-422-expected_response2] FAILED tests/test_tutorial/test_query_params/test_tutorial005.py::test[/items/foo-422-expected_response3] FAILED tests/test_tutorial/test_query_params/test_tutorial006.py::test[/openapi.json-200-expected_response0] FAILED tests/test_tutorial/test_query_params/test_tutorial006.py::test[/items/foo?needy=very-200-expected_response1] FAILED tests/test_tutorial/test_query_params/test_tutorial006.py::test[/items/foo?skip=a&limit=b-422-expected_response2] FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py::test_query_params_str_validations[None-None-200-expected_response0] FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py::test_query_params_str_validations[item-query-fixedquery-200-expected_response1] FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py::test_query_params_str_validations[q-fixedquery-200-expected_response2] FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py::test_query_params_str_validations[item-query-nonregexquery-422-expected_response3] FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py::test_openapi_schema FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py::test_multi_query_values FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py::test_query_no_values FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py::test_openapi_schema FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py::test_default_query_values FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py::test_multi_query_values FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py::test_openapi_schema FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py::test_multi_query_values FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py::test_query_no_values FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_post_form_no_body FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_post_body_json FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_post_file FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_post_large_file FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_post_upload_file FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_openapi_schema FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_post_form_no_body FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_post_body_json FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_post_files FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_post_upload_file FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_get_root FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_post_body_form[/login/-body0-200-expected_response0] FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_post_body_form[/login/-body1-422-expected_response1] FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_post_body_form[/login/-body2-422-expected_response2] FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_post_body_form[/login/-None-422-expected_response3] FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_post_body_json FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_post_form_no_body FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_post_form_no_file FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_post_body_json FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_post_file_no_token FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_post_files_and_token FAILED tests/test_tutorial/test_response_change_status_code/test_tutorial001.py::test_path_operation FAILED tests/test_tutorial/test_response_cookies/test_tutorial001.py::test_path_operation FAILED tests/test_tutorial/test_response_cookies/test_tutorial002.py::test_path_operation FAILED tests/test_tutorial/test_response_headers/test_tutorial001.py::test_path_operation FAILED tests/test_tutorial/test_response_headers/test_tutorial002.py::test_path_operation FAILED tests/test_tutorial/test_response_model/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_response_model/test_tutorial003.py::test_post_user FAILED tests/test_tutorial/test_response_model/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_response_model/test_tutorial004.py::test_get[/items/foo-data0] FAILED tests/test_tutorial/test_response_model/test_tutorial004.py::test_get[/items/bar-data1] FAILED tests/test_tutorial/test_response_model/test_tutorial004.py::test_get[/items/baz-data2] FAILED tests/test_tutorial/test_response_model/test_tutorial005.py::test_openapi_schema FAILED tests/test_tutorial/test_response_model/test_tutorial005.py::test_read_item_name FAILED tests/test_tutorial/test_response_model/test_tutorial005.py::test_read_item_public_data FAILED tests/test_tutorial/test_response_model/test_tutorial006.py::test_openapi_schema FAILED tests/test_tutorial/test_response_model/test_tutorial006.py::test_read_item_name FAILED tests/test_tutorial/test_response_model/test_tutorial006.py::test_read_item_public_data FAILED tests/test_tutorial/test_security/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_security/test_tutorial001.py::test_no_token FAILED tests/test_tutorial/test_security/test_tutorial001.py::test_token - At... FAILED tests/test_tutorial/test_security/test_tutorial001.py::test_incorrect_token FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_login - At... FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_login_incorrect_password FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_login_incorrect_username FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_no_token FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_token - At... FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_incorrect_token FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_incorrect_token_type FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_inactive_user FAILED tests/test_tutorial/test_security/test_tutorial006.py::test_openapi_schema FAILED tests/test_tutorial/test_security/test_tutorial006.py::test_security_http_basic FAILED tests/test_tutorial/test_security/test_tutorial006.py::test_security_http_basic_no_credentials FAILED tests/test_tutorial/test_security/test_tutorial006.py::test_security_http_basic_invalid_credentials FAILED tests/test_tutorial/test_security/test_tutorial006.py::test_security_http_basic_non_basic_credentials FAILED tests/test_tutorial/test_settings/test_app02.py::test_setting_override FAILED tests/test_tutorial/test_sql_databases/test_testing_databases.py::test_testing_dbs FAILED tests/test_tutorial/test_sub_applications/test_tutorial001.py::test_openapi_schema_main FAILED tests/test_tutorial/test_sub_applications/test_tutorial001.py::test_main FAILED tests/test_tutorial/test_sub_applications/test_tutorial001.py::test_openapi_schema_sub FAILED tests/test_tutorial/test_sub_applications/test_tutorial001.py::test_sub FAILED tests/test_tutorial/test_templates/test_tutorial001.py::test_main - At... FAILED tests/test_tutorial/test_testing/test_main.py::test_read_main - Attrib... FAILED tests/test_tutorial/test_testing/test_main.py::test_openapi_schema - A... FAILED tests/test_tutorial/test_testing/test_main.py::test_main - AttributeEr... FAILED tests/test_tutorial/test_testing/test_tutorial001.py::test_read_main FAILED tests/test_tutorial/test_testing/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_testing/test_tutorial001.py::test_main - Attr... FAILED tests/test_tutorial/test_testing/test_tutorial002.py::test_read_main FAILED tests/test_tutorial/test_testing/test_tutorial002.py::test_websocket FAILED tests/test_tutorial/test_testing/test_tutorial002.py::test_main - Attr... FAILED tests/test_tutorial/test_testing/test_tutorial002.py::test_ws - Attrib... FAILED tests/test_tutorial/test_testing/test_tutorial003.py::test_read_items FAILED tests/test_tutorial/test_testing/test_tutorial003.py::test_main - Attr... FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items_with_q FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items_with_params FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items_run FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items_with_q_run FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items_with_params_run FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_users FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_users_with_q FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_users_with_params FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_normal_app FAILED tests/test_tutorial/test_websockets/test_tutorial001.py::test_main - A... FAILED tests/test_tutorial/test_websockets/test_tutorial001.py::test_websocket FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_main - A... FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_websocket_with_cookie FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_websocket_with_header FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_websocket_with_header_and_query FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_websocket_no_credentials FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_websocket_invalid_data FAILED tests/test_tutorial/test_websockets/test_tutorial003.py::test_websocket_handle_disconnection FAILED tests/test_tutorial/test_wsgi/test_tutorial001.py::test_flask - Attrib... FAILED tests/test_tutorial/test_wsgi/test_tutorial001.py::test_app - Attribut... ERROR tests/test_tutorial/test_extending_openapi/test_tutorial002.py::test_swagger_ui_html ERROR tests/test_tutorial/test_extending_openapi/test_tutorial002.py::test_swagger_ui_oauth2_redirect_html ERROR tests/test_tutorial/test_extending_openapi/test_tutorial002.py::test_redoc_html ERROR tests/test_tutorial/test_extending_openapi/test_tutorial002.py::test_api ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_openapi_schema ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_create_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_get_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_inexistent_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_get_users ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_create_item ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_read_items ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_openapi_schema ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_create_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_get_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_inexistent_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_get_users ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_create_item ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_read_items ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_openapi_schema ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_create_user ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_get_user ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_inexistent_user ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_get_users ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_get_slowusers ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_create_item ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_read_items =========== 782 failed, 84 passed, 3 deselected, 26 errors in 38.87s =========== E: pybuild pybuild:367: test: plugin custom failed with: exit code=1: PYTHONPATH=/<>/build/lib/ python3.10 -m pytest tests/ --ignore=tests/test_default_response_class.py --ignore=tests/test_tutorial/test_security/test_tutorial005.py --ignore=tests/test_response_by_alias.py -k ' not test_get_custom_response' I: pybuild base:237: PYTHONPATH=/<>/build/lib/ python3.9 -m pytest tests/ --ignore=tests/test_default_response_class.py --ignore=tests/test_tutorial/test_security/test_tutorial005.py --ignore=tests/test_response_by_alias.py -k ' not test_get_custom_response' ============================= test session starts ============================== platform linux -- Python 3.9.9, pytest-6.2.5, py-1.10.0, pluggy-0.13.0 rootdir: /<> plugins: asyncio-0.16.0, anyio-0.0.0 collected 895 items / 3 deselected / 892 selected tests/test_additional_properties.py FF [ 0%] tests/test_additional_response_extra.py FF [ 0%] tests/test_additional_responses_bad.py F [ 0%] tests/test_additional_responses_custom_model_in_callback.py F [ 0%] tests/test_additional_responses_custom_validationerror.py F [ 0%] tests/test_additional_responses_default_validationerror.py F [ 0%] tests/test_additional_responses_response_class.py F [ 1%] tests/test_additional_responses_router.py FFFF [ 1%] tests/test_application.py FFFFFFFF [ 2%] tests/test_callable_endpoint.py F [ 2%] tests/test_custom_route_class.py FFFF. [ 3%] tests/test_custom_swagger_ui_redirect.py FFF [ 3%] tests/test_datastructures.py ... [ 3%] tests/test_datetime_custom_encoder.py F [ 3%] tests/test_default_response_class_router.py FFFFFFFFFFFFFF [ 5%] tests/test_dependency_cache.py FFF [ 5%] tests/test_dependency_class.py FFFFFFFF [ 6%] tests/test_dependency_contextmanager.py FFFFFFFFFFFFFFFFFF [ 8%] tests/test_dependency_duplicates.py FFFFF [ 9%] tests/test_dependency_overrides.py FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF [ 12%] tests/test_dependency_security_overrides.py FFF [ 13%] tests/test_deprecated_openapi_prefix.py FF [ 13%] tests/test_duplicate_models_openapi.py FF [ 13%] tests/test_empty_router.py F. [ 13%] tests/test_exception_handlers.py FF [ 14%] tests/test_extra_routes.py FFFFFFFF [ 14%] tests/test_fakeasync.py . [ 15%] tests/test_filter_pydantic_sub_model.py FFF [ 15%] tests/test_forms_from_non_typing_sequences.py FFF [ 15%] tests/test_get_request_body.py FF [ 15%] tests/test_http_connection_injection.py FF [ 16%] tests/test_include_route.py F [ 16%] tests/test_include_router_defaults_overrides.py FFFFFFFFFFFFFFFFFFFFFFFF [ 18%] FFFFFFFFFFFFFFFFFFF [ 21%] tests/test_infer_param_optionality.py FFFFFFFFFF [ 22%] tests/test_inherited_custom_class.py F [ 22%] tests/test_invalid_path_param.py ....... [ 23%] tests/test_invalid_sequence_param.py .... [ 23%] tests/test_jsonable_encoder.py .............. [ 25%] tests/test_local_docs.py ..... [ 25%] tests/test_multi_body_errors.py FFFF [ 26%] tests/test_multi_query_errors.py FFF [ 26%] tests/test_multipart_installation.py .......... [ 27%] tests/test_no_swagger_ui_redirect.py FFF [ 27%] tests/test_openapi_servers.py FF [ 28%] tests/test_operations_signatures.py . [ 28%] tests/test_param_class.py FF [ 28%] tests/test_param_in_path_and_dependency.py FF [ 28%] tests/test_params_repr.py ............................... [ 32%] tests/test_path.py FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF [ 38%] FFFFFFFFFFFFFFFFFFFFFFF [ 40%] tests/test_put_no_body.py FFF [ 41%] tests/test_query.py FFFFFFFFFFFFFFFFFFFFFFFF [ 43%] tests/test_repeated_cookie_headers.py F [ 43%] tests/test_repeated_dependency_schema.py FF [ 44%] tests/test_request_body_parameters_media_type.py F [ 44%] tests/test_response_change_status_code.py F [ 44%] tests/test_response_class_no_mediatype.py F [ 44%] tests/test_response_code_no_body.py F [ 44%] tests/test_response_model_invalid.py .... [ 44%] tests/test_response_model_sub_types.py FF [ 45%] tests/test_router_events.py F [ 45%] tests/test_router_prefix_with_template.py F [ 45%] tests/test_security_api_key_cookie.py FFF [ 45%] tests/test_security_api_key_cookie_optional.py FFF [ 46%] tests/test_security_api_key_header.py FFF [ 46%] tests/test_security_api_key_header_optional.py FFF [ 46%] tests/test_security_api_key_query.py FFF [ 47%] tests/test_security_api_key_query_optional.py FFF [ 47%] tests/test_security_http_base.py FFF [ 47%] tests/test_security_http_base_optional.py FFF [ 48%] tests/test_security_http_basic_optional.py FFFFF [ 48%] tests/test_security_http_basic_realm.py FFFFF [ 49%] tests/test_security_http_bearer.py FFFF [ 49%] tests/test_security_http_bearer_optional.py FFFF [ 50%] tests/test_security_http_digest.py FFFF [ 50%] tests/test_security_http_digest_optional.py FFFF [ 51%] tests/test_security_oauth2.py FFFFFFFF [ 51%] tests/test_security_oauth2_authorization_code_bearer.py FFFF [ 52%] tests/test_security_oauth2_optional.py FFFFFFFF [ 53%] tests/test_security_oauth2_password_bearer_optional.py FFFF [ 53%] tests/test_security_openid_connect.py FFFF [ 54%] tests/test_security_openid_connect_optional.py FFFF [ 54%] tests/test_serialize_response.py FFF [ 54%] tests/test_serialize_response_dataclass.py FFF [ 55%] tests/test_serialize_response_model.py FFFFFFFF [ 56%] tests/test_skip_defaults.py FFFFF [ 56%] tests/test_starlette_exception.py FFFFF [ 57%] tests/test_starlette_urlconvertors.py FFF. [ 57%] tests/test_sub_callbacks.py FF [ 57%] tests/test_swagger_ui_init_oauth.py FF [ 58%] tests/test_union_body.py FFF [ 58%] tests/test_union_inherited_body.py FFF [ 58%] tests/test_validate_response.py FFF [ 59%] tests/test_validate_response_dataclass.py FFF [ 59%] tests/test_validate_response_recursive.py F [ 59%] tests/test_ws_router.py FFFFFF [ 60%] tests/test_modules_same_name_body/test_main.py FFFFF [ 60%] tests/test_tutorial/test_additional_responses/test_tutorial001.py FFF [ 61%] tests/test_tutorial/test_additional_responses/test_tutorial002.py FFF [ 61%] tests/test_tutorial/test_additional_responses/test_tutorial003.py FFF [ 61%] tests/test_tutorial/test_additional_responses/test_tutorial004.py FFF [ 62%] tests/test_tutorial/test_additional_status_codes/test_tutorial001.py FF [ 62%] tests/test_tutorial/test_advanced_middleware/test_tutorial001.py F [ 62%] tests/test_tutorial/test_advanced_middleware/test_tutorial002.py F [ 62%] tests/test_tutorial/test_advanced_middleware/test_tutorial003.py F [ 62%] tests/test_tutorial/test_async_sql_databases/test_tutorial001.py FF [ 63%] tests/test_tutorial/test_async_tests/test_main.py FF [ 63%] tests/test_tutorial/test_background_tasks/test_tutorial001.py F [ 63%] tests/test_tutorial/test_background_tasks/test_tutorial002.py F [ 63%] tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py FF [ 63%] tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py FF [ 63%] tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py FF [ 64%] tests/test_tutorial/test_behind_a_proxy/test_tutorial004.py FF [ 64%] tests/test_tutorial/test_bigger_applications/test_main.py FFFFFFFFFFFFFF [ 65%] FFFFFFFFF [ 66%] tests/test_tutorial/test_body/test_tutorial001.py FFFFFFFFFF [ 68%] tests/test_tutorial/test_body_fields/test_tutorial001.py FFFF [ 68%] tests/test_tutorial/test_body_multiple_params/test_tutorial001.py FFFFF [ 69%] tests/test_tutorial/test_body_multiple_params/test_tutorial003.py FFFF [ 69%] tests/test_tutorial/test_body_nested_models/test_tutorial009.py FFF [ 69%] tests/test_tutorial/test_body_updates/test_tutorial001.py FFF [ 70%] tests/test_tutorial/test_conditional_openapi/test_tutorial001.py FF [ 70%] tests/test_tutorial/test_cookie_params/test_tutorial001.py FFFFF [ 70%] tests/test_tutorial/test_cors/test_tutorial001.py F [ 71%] tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py FF [ 71%] F [ 71%] tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py FF [ 71%] [ 71%] tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py FF [ 71%] [ 71%] tests/test_tutorial/test_custom_response/test_tutorial001.py F [ 71%] tests/test_tutorial/test_custom_response/test_tutorial001b.py F [ 72%] tests/test_tutorial/test_custom_response/test_tutorial004.py F [ 72%] tests/test_tutorial/test_custom_response/test_tutorial005.py FF [ 72%] tests/test_tutorial/test_custom_response/test_tutorial006.py F [ 72%] tests/test_tutorial/test_custom_response/test_tutorial007.py F [ 72%] tests/test_tutorial/test_custom_response/test_tutorial008.py F [ 72%] tests/test_tutorial/test_dependencies/test_tutorial001.py FFFFFFF [ 73%] tests/test_tutorial/test_dependencies/test_tutorial004.py FFFFFFF [ 74%] tests/test_tutorial/test_dependencies/test_tutorial006.py FFFFF [ 74%] tests/test_tutorial/test_dependencies/test_tutorial012.py FFFFFFFFF [ 75%] tests/test_tutorial/test_events/test_tutorial001.py F [ 76%] tests/test_tutorial/test_events/test_tutorial002.py F [ 76%] tests/test_tutorial/test_extending_openapi/test_tutorial001.py FF [ 76%] tests/test_tutorial/test_extending_openapi/test_tutorial002.py EEEE [ 76%] tests/test_tutorial/test_extra_data_types/test_tutorial001.py FF [ 77%] tests/test_tutorial/test_extra_models/test_tutorial003.py FFF [ 77%] tests/test_tutorial/test_extra_models/test_tutorial004.py FF [ 77%] tests/test_tutorial/test_extra_models/test_tutorial005.py FF [ 77%] tests/test_tutorial/test_first_steps/test_tutorial001.py FFF [ 78%] tests/test_tutorial/test_handling_errors/test_tutorial001.py FFF [ 78%] tests/test_tutorial/test_handling_errors/test_tutorial002.py FFF [ 78%] tests/test_tutorial/test_handling_errors/test_tutorial003.py FFF [ 79%] tests/test_tutorial/test_handling_errors/test_tutorial004.py FFFF [ 79%] tests/test_tutorial/test_handling_errors/test_tutorial005.py FFF [ 79%] tests/test_tutorial/test_handling_errors/test_tutorial006.py FFFF [ 80%] tests/test_tutorial/test_header_params/test_tutorial001.py FFFF [ 80%] tests/test_tutorial/test_metadata/test_tutorial001.py FF [ 81%] tests/test_tutorial/test_metadata/test_tutorial004.py FF [ 81%] tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py FF. [ 81%] tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial001.py F [ 81%] F [ 81%] tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial002.py F [ 81%] F [ 82%] tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial003.py F [ 82%] F [ 82%] tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py F [ 82%] F [ 82%] tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py F [ 82%] F [ 82%] tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py F [ 82%] FFF [ 83%] tests/test_tutorial/test_path_params/test_tutorial004.py FFF [ 83%] tests/test_tutorial/test_path_params/test_tutorial005.py FFFFF [ 84%] tests/test_tutorial/test_query_params/test_tutorial005.py FFFF [ 84%] tests/test_tutorial/test_query_params/test_tutorial006.py FFF [ 84%] tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py F [ 84%] FFFF [ 85%] tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py F [ 85%] FF [ 85%] tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py F [ 85%] FF [ 86%] tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py F [ 86%] FF [ 86%] tests/test_tutorial/test_request_files/test_tutorial001.py FFFFFF [ 87%] tests/test_tutorial/test_request_files/test_tutorial002.py FFFFFF [ 87%] tests/test_tutorial/test_request_forms/test_tutorial001.py FFFFFF [ 88%] tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py FFF [ 88%] FFF [ 89%] tests/test_tutorial/test_response_change_status_code/test_tutorial001.py F [ 89%] [ 89%] tests/test_tutorial/test_response_cookies/test_tutorial001.py F [ 89%] tests/test_tutorial/test_response_cookies/test_tutorial002.py F [ 89%] tests/test_tutorial/test_response_headers/test_tutorial001.py F [ 89%] tests/test_tutorial/test_response_headers/test_tutorial002.py F [ 89%] tests/test_tutorial/test_response_model/test_tutorial003.py FF [ 89%] tests/test_tutorial/test_response_model/test_tutorial004.py FFFF [ 90%] tests/test_tutorial/test_response_model/test_tutorial005.py FFF [ 90%] tests/test_tutorial/test_response_model/test_tutorial006.py FFF [ 91%] tests/test_tutorial/test_security/test_tutorial001.py FFFF [ 91%] tests/test_tutorial/test_security/test_tutorial003.py FFFFFFFFF [ 92%] tests/test_tutorial/test_security/test_tutorial006.py FFFFF [ 93%] tests/test_tutorial/test_settings/test_app02.py F [ 93%] tests/test_tutorial/test_sql_databases/test_sql_databases.py EEEEEEE [ 93%] tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py E [ 94%] EEEEEE [ 94%] tests/test_tutorial/test_sql_databases/test_testing_databases.py F [ 94%] tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py E [ 94%] EEEEEEE [ 95%] tests/test_tutorial/test_sub_applications/test_tutorial001.py FFFF [ 96%] tests/test_tutorial/test_templates/test_tutorial001.py F [ 96%] tests/test_tutorial/test_testing/test_main.py FFF [ 96%] tests/test_tutorial/test_testing/test_tutorial001.py FFF [ 96%] tests/test_tutorial/test_testing/test_tutorial002.py FFFF [ 97%] tests/test_tutorial/test_testing/test_tutorial003.py FF [ 97%] tests/test_tutorial/test_testing_dependencies/test_tutorial001.py FFFFFF [ 98%] FFFF [ 98%] tests/test_tutorial/test_websockets/test_tutorial001.py FF [ 98%] tests/test_tutorial/test_websockets/test_tutorial002.py FFFFFF [ 99%] tests/test_tutorial/test_websockets/test_tutorial003.py F [ 99%] tests/test_tutorial/test_wsgi/test_tutorial001.py FF [100%] ==================================== ERRORS ==================================== ____________________ ERROR at setup of test_swagger_ui_html ____________________ @pytest.fixture(scope="module") def client(): static_dir: Path = Path(os.getcwd()) / "static" print(static_dir) static_dir.mkdir(exist_ok=True) from docs_src.extending_openapi.tutorial002 import app > with TestClient(app) as client: tests/test_tutorial/test_extending_openapi/test_tutorial002.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ---------------------------- Captured stdout setup ----------------------------- /<>/static ____________ ERROR at setup of test_swagger_ui_oauth2_redirect_html ____________ @pytest.fixture(scope="module") def client(): static_dir: Path = Path(os.getcwd()) / "static" print(static_dir) static_dir.mkdir(exist_ok=True) from docs_src.extending_openapi.tutorial002 import app > with TestClient(app) as client: tests/test_tutorial/test_extending_openapi/test_tutorial002.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_redoc_html _______________________ @pytest.fixture(scope="module") def client(): static_dir: Path = Path(os.getcwd()) / "static" print(static_dir) static_dir.mkdir(exist_ok=True) from docs_src.extending_openapi.tutorial002 import app > with TestClient(app) as client: tests/test_tutorial/test_extending_openapi/test_tutorial002.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError __________________________ ERROR at setup of test_api __________________________ @pytest.fixture(scope="module") def client(): static_dir: Path = Path(os.getcwd()) / "static" print(static_dir) static_dir.mkdir(exist_ok=True) from docs_src.extending_openapi.tutorial002 import app > with TestClient(app) as client: tests/test_tutorial/test_extending_openapi/test_tutorial002.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_openapi_schema _____________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_user ______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_user ________________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_inexistent_user ____________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_users _______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_item ______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_read_items _______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import main # Ensure import side effects are re-executed importlib.reload(main) > with TestClient(main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases.py:295: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_openapi_schema _____________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_user ______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_user ________________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_inexistent_user ____________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_users _______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_item ______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_read_items _______________________ @pytest.fixture(scope="module") def client(): test_db = Path("./sql_app.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app import alt_main # Ensure import side effects are re-executed importlib.reload(alt_main) > with TestClient(alt_main.app) as c: tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py:296: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_openapi_schema _____________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_user ______________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_user ________________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________ ERROR at setup of test_inexistent_user ____________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________ ERROR at setup of test_get_users _______________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _____________________ ERROR at setup of test_get_slowusers _____________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_create_item ______________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________ ERROR at setup of test_read_items _______________________ @pytest.fixture(scope="module") def client(): # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases_peewee.sql_app.main import app test_db = Path("./test.db") > with TestClient(app) as c: tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py:338: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError =================================== FAILURES =================================== ______________________ test_additional_properties_schema _______________________ def test_additional_properties_schema(): > response = client.get("/openapi.json") tests/test_additional_properties.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_additional_properties_post ________________________ def test_additional_properties_post(): > response = client.post("/foo", json={"items": {"foo": 1, "bar": 2}}) tests/test_additional_properties.py:108: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/foo', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'31'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_response_extra.py:44: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/items/") tests/test_additional_response_extra.py:50: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): with pytest.raises(ValueError): > client.get("/openapi.json") tests/test_additional_responses_bad.py:40: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_responses_custom_model_in_callback.py:136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_responses_custom_validationerror.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_responses_default_validationerror.py:83: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_responses_response_class.py:115: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_additional_responses_router.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________________ test_a ____________________________________ def test_a(): > response = client.get("/a") tests/test_additional_responses_router.py:97: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________________ test_b ____________________________________ def test_b(): > response = client.get("/b") tests/test_additional_responses_router.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/b', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________________ test_c ____________________________________ def test_c(): > response = client.get("/c") tests/test_additional_responses_router.py:109: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/c', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/api_route-200-expected_response0] _______________ path = '/api_route', expected_status = 200 expected_response = {'message': 'Hello World'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/api_route", 200, {"message": "Hello World"}), ("/non_decorated_route", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_application.py:1136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/api_route', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/non_decorated_route-200-expected_response1] __________ path = '/non_decorated_route', expected_status = 200 expected_response = {'message': 'Hello World'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/api_route", 200, {"message": "Hello World"}), ("/non_decorated_route", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_application.py:1136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/non_decorated_route' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_get_path[/nonexistent-404-expected_response2] ______________ path = '/nonexistent', expected_status = 404 expected_response = {'detail': 'Not Found'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/api_route", 200, {"message": "Hello World"}), ("/non_decorated_route", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_application.py:1136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/nonexistent', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/openapi.json-200-expected_response3] ______________ path = '/openapi.json', expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type...Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Get Bool Id'}}, ...}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/api_route", 200, {"message": "Hello World"}), ("/non_decorated_route", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_application.py:1136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_swagger_ui ________________________________ def test_swagger_ui(): > response = client.get("/docs") tests/test_application.py:1142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_swagger_ui_oauth2_redirect ________________________ def test_swagger_ui_oauth2_redirect(): > response = client.get("/docs/oauth2-redirect") tests/test_application.py:1153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs/oauth2-redirect' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_redoc __________________________________ def test_redoc(): > response = client.get("/redoc") tests/test_application.py:1160: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/redoc', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_enum_status_code_response ________________________ def test_enum_status_code_response(): > response = client.get("/enum-status-code") tests/test_application.py:1167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/enum-status-code', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_partial _________________________________ def test_partial(): > response = client.get("/?q=bar") tests/test_callable_endpoint.py:23: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = 'q=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/a-200-expected_response0] ___________________ path = '/a', expected_status = 200, expected_response = {'msg': 'A'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/a", 200, {"msg": "A"}), ("/a/b", 200, {"msg": "B"}), ("/a/b/c", 200, {"msg": "C"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_custom_route_class.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/a/b-200-expected_response1] __________________ path = '/a/b', expected_status = 200, expected_response = {'msg': 'B'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/a", 200, {"msg": "A"}), ("/a/b", 200, {"msg": "B"}), ("/a/b/c", 200, {"msg": "C"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_custom_route_class.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a/b', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/a/b/c-200-expected_response2] _________________ path = '/a/b/c', expected_status = 200, expected_response = {'msg': 'C'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/a", 200, {"msg": "A"}), ("/a/b", 200, {"msg": "B"}), ("/a/b/c", 200, {"msg": "C"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_custom_route_class.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a/b/c', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/openapi.json-200-expected_response3] ______________ path = '/openapi.json', expected_status = 200 expected_response = {'info': {'title': 'FastAPI', 'version': '0.1.0'}, 'openapi': '3.0.2', 'paths': {'/a/': {'get': {'operationId': 'get_a...t_c_a_b_c__get', 'responses': {'200': {'content': {...}, 'description': 'Successful Response'}}, 'summary': 'Get C'}}}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/a", 200, {"msg": "A"}), ("/a/b", 200, {"msg": "B"}), ("/a/b/c", 200, {"msg": "C"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_custom_route_class.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_swagger_ui ________________________________ def test_swagger_ui(): > response = client.get("/docs") tests/test_custom_swagger_ui_redirect.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_swagger_ui_oauth2_redirect ________________________ def test_swagger_ui_oauth2_redirect(): > response = client.get(swagger_ui_oauth2_redirect_url) tests/test_custom_swagger_ui_redirect.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs/redirect', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_response _________________________________ def test_response(): > response = client.get("/items/") tests/test_custom_swagger_ui_redirect.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_dt ____________________________________ def test_dt(): > with client: tests/test_datetime_custom_encoder.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________________ test_app ___________________________________ def test_app(): > with client: tests/test_default_response_class_router.py:112: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________________ test_app_override _______________________________ def test_app_override(): > with client: tests/test_default_response_class_router.py:119: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ________________________________ test_router_a _________________________________ def test_router_a(): > with client: tests/test_default_response_class_router.py:126: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________________ test_router_a_override ____________________________ def test_router_a_override(): > with client: tests/test_default_response_class_router.py:133: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________________ test_router_a_a ________________________________ def test_router_a_a(): > with client: tests/test_default_response_class_router.py:140: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________ test_router_a_a_override ___________________________ def test_router_a_a_override(): > with client: tests/test_default_response_class_router.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________________ test_router_a_b ________________________________ def test_router_a_b(): > with client: tests/test_default_response_class_router.py:154: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________ test_router_a_b_override ___________________________ def test_router_a_b_override(): > with client: tests/test_default_response_class_router.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ________________________________ test_router_b _________________________________ def test_router_b(): > with client: tests/test_default_response_class_router.py:168: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________________ test_router_b_override ____________________________ def test_router_b_override(): > with client: tests/test_default_response_class_router.py:175: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________________ test_router_b_a ________________________________ def test_router_b_a(): > with client: tests/test_default_response_class_router.py:182: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________ test_router_b_a_override ___________________________ def test_router_b_a_override(): > with client: tests/test_default_response_class_router.py:189: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ______________________________ test_router_b_a_c _______________________________ def test_router_b_a_c(): > with client: tests/test_default_response_class_router.py:196: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError __________________________ test_router_b_a_c_override __________________________ def test_router_b_a_c_override(): > with client: tests/test_default_response_class_router.py:203: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _____________________________ test_normal_counter ______________________________ def test_normal_counter(): counter_holder["counter"] = 0 > response = client.get("/counter/") tests/test_dependency_cache.py:43: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/counter/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_sub_counter _______________________________ def test_sub_counter(): counter_holder["counter"] = 0 > response = client.get("/sub-counter/") tests/test_dependency_cache.py:53: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sub-counter/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_sub_counter_no_cache ___________________________ def test_sub_counter_no_cache(): counter_holder["counter"] = 0 > response = client.get("/sub-counter-no-cache/") tests/test_dependency_cache.py:63: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sub-counter-no-cache/' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_class_dependency[/callable-dependency-callable-dependency] ________ route = '/callable-dependency', value = 'callable-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/callable-dependency' query = 'value=callable-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_class_dependency[/callable-gen-dependency-callable-gen-dependency] ____ route = '/callable-gen-dependency', value = 'callable-gen-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/callable-gen-dependency' query = 'value=callable-gen-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/async-callable-dependency-async-callable-dependency] __ route = '/async-callable-dependency', value = 'async-callable-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/async-callable-dependency' query = 'value=async-callable-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/async-callable-gen-dependency-async-callable-gen-dependency] _ route = '/async-callable-gen-dependency' value = 'async-callable-gen-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/async-callable-gen-dependency' query = 'value=async-callable-gen-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/synchronous-method-dependency-synchronous-method-dependency] _ route = '/synchronous-method-dependency' value = 'synchronous-method-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/synchronous-method-dependency' query = 'value=synchronous-method-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/synchronous-method-gen-dependency-synchronous-method-gen-dependency] _ route = '/synchronous-method-gen-dependency' value = 'synchronous-method-gen-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/synchronous-method-gen-dependency' query = 'value=synchronous-method-gen-dependency', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/asynchronous-method-dependency-asynchronous-method-dependency] _ route = '/asynchronous-method-dependency' value = 'asynchronous-method-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/asynchronous-method-dependency' query = 'value=asynchronous-method-dependency', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_class_dependency[/asynchronous-method-gen-dependency-asynchronous-method-gen-dependency] _ route = '/asynchronous-method-gen-dependency' value = 'asynchronous-method-gen-dependency' @pytest.mark.parametrize( "route,value", [ ("/callable-dependency", "callable-dependency"), ("/callable-gen-dependency", "callable-gen-dependency"), ("/async-callable-dependency", "async-callable-dependency"), ("/async-callable-gen-dependency", "async-callable-gen-dependency"), ("/synchronous-method-dependency", "synchronous-method-dependency"), ("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"), ("/asynchronous-method-dependency", "asynchronous-method-dependency"), ("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"), ], ) def test_class_dependency(route, value): > response = client.get(route, params={"value": value}) tests/test_dependency_class.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/asynchronous-method-gen-dependency' query = 'value=asynchronous-method-gen-dependency', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_async_state _______________________________ def test_async_state(): assert state["/async"] == "asyncgen not started" > response = client.get("/async") tests/test_dependency_contextmanager.py:208: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/async', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_sync_state ________________________________ def test_sync_state(): assert state["/sync"] == "generator not started" > response = client.get("/sync") tests/test_dependency_contextmanager.py:216: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_async_raise_other ____________________________ def test_async_raise_other(): assert state["/async_raise"] == "asyncgen raise not started" with pytest.raises(OtherDependencyError): > client.get("/async_raise_other") tests/test_dependency_contextmanager.py:225: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/async_raise_other', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_sync_raise_other _____________________________ def test_sync_raise_other(): assert state["/sync_raise"] == "generator raise not started" with pytest.raises(OtherDependencyError): > client.get("/sync_raise_other") tests/test_dependency_contextmanager.py:233: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_raise_other', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_async_raise _______________________________ def test_async_raise(): > response = client.get("/async_raise") tests/test_dependency_contextmanager.py:239: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/async_raise', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_context_b ________________________________ def test_context_b(): > response = client.get("/context_b") tests/test_dependency_contextmanager.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/context_b', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_context_b_raise _____________________________ def test_context_b_raise(): with pytest.raises(OtherDependencyError): > client.get("/context_b_raise") tests/test_dependency_contextmanager.py:257: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/context_b_raise', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_background_tasks _____________________________ def test_background_tasks(): > response = client.get("/context_b_bg") tests/test_dependency_contextmanager.py:263: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/context_b_bg', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_sync_raise ________________________________ def test_sync_raise(): > response = client.get("/sync_raise") tests/test_dependency_contextmanager.py:274: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_raise', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_sync_async_state _____________________________ def test_sync_async_state(): > response = client.get("/sync_async") tests/test_dependency_contextmanager.py:282: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_async', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_sync_sync_state _____________________________ def test_sync_sync_state(): > response = client.get("/sync_sync") tests/test_dependency_contextmanager.py:289: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_sync', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_sync_async_raise_other __________________________ def test_sync_async_raise_other(): with pytest.raises(OtherDependencyError): > client.get("/sync_async_raise_other") tests/test_dependency_contextmanager.py:297: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_async_raise_other' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_sync_sync_raise_other __________________________ def test_sync_sync_raise_other(): with pytest.raises(OtherDependencyError): > client.get("/sync_sync_raise_other") tests/test_dependency_contextmanager.py:304: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_sync_raise_other' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_sync_async_raise _____________________________ def test_sync_async_raise(): > response = client.get("/sync_async_raise") tests/test_dependency_contextmanager.py:310: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_async_raise', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_sync_sync_raise _____________________________ def test_sync_sync_raise(): > response = client.get("/sync_sync_raise") tests/test_dependency_contextmanager.py:318: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_sync_raise', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_sync_context_b ______________________________ def test_sync_context_b(): > response = client.get("/sync_context_b") tests/test_dependency_contextmanager.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_context_b', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_sync_context_b_raise ___________________________ def test_sync_context_b_raise(): with pytest.raises(OtherDependencyError): > client.get("/sync_context_b_raise") tests/test_dependency_contextmanager.py:336: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_context_b_raise' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_sync_background_tasks __________________________ def test_sync_background_tasks(): > response = client.get("/sync_context_b_bg") tests/test_dependency_contextmanager.py:342: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sync_context_b_bg', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_dependency_duplicates.py:192: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_no_duplicates_invalid __________________________ def test_no_duplicates_invalid(): > response = client.post("/no-duplicates", json={"item": {"data": "myitem"}}) tests/test_dependency_duplicates.py:198: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/no-duplicates', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'28'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_no_duplicates ______________________________ def test_no_duplicates(): > response = client.post( "/no-duplicates", json={"item": {"data": "myitem"}, "item2": {"data": "myitem2"}}, ) tests/test_dependency_duplicates.py:212: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/no-duplicates', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'58'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_duplicates ________________________________ def test_duplicates(): > response = client.post("/with-duplicates", json={"data": "myitem"}) tests/test_dependency_duplicates.py:221: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/with-duplicates', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'18'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_sub_duplicates ______________________________ def test_sub_duplicates(): > response = client.post("/with-duplicates-sub", json={"data": "myitem"}) tests/test_dependency_duplicates.py:227: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/with-duplicates-sub' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'18'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_normal_app[/main-depends/-422-expected0] _________________ url = '/main-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'q'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_normal_app[/main-depends/?q=foo-200-expected1] ______________ url = '/main-depends/?q=foo', status_code = 200 expected = {'in': 'main-depends', 'params': {'limit': 100, 'q': 'foo', 'skip': 0}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____ test_normal_app[/main-depends/?q=foo&skip=100&limit=200-200-expected2] ____ url = '/main-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'main-depends', 'params': {'limit': 200, 'q': 'foo', 'skip': 100}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_normal_app[/decorator-depends/-422-expected3] ______________ url = '/decorator-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'q'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_normal_app[/decorator-depends/?q=foo-200-expected4] ___________ url = '/decorator-depends/?q=foo', status_code = 200 expected = {'in': 'decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_normal_app[/decorator-depends/?q=foo&skip=100&limit=200-200-expected5] __ url = '/decorator-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_normal_app[/router-depends/-422-expected6] ________________ url = '/router-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'q'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_normal_app[/router-depends/?q=foo-200-expected7] _____________ url = '/router-depends/?q=foo', status_code = 200 expected = {'in': 'router-depends', 'params': {'limit': 100, 'q': 'foo', 'skip': 0}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_normal_app[/router-depends/?q=foo&skip=100&limit=200-200-expected8] ___ url = '/router-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'router-depends', 'params': {'limit': 200, 'q': 'foo', 'skip': 100}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_normal_app[/router-decorator-depends/-422-expected9] ___________ url = '/router-decorator-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'q'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_normal_app[/router-decorator-depends/?q=foo-200-expected10] _______ url = '/router-decorator-depends/?q=foo', status_code = 200 expected = {'in': 'router-decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_normal_app[/router-decorator-depends/?q=foo&skip=100&limit=200-200-expected11] _ url = '/router-decorator-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'router-decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?q=foo", 200, {"in": "decorator-depends"}), ( "/decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "decorator-depends"}, ), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 0, "limit": 100}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 100, "limit": 200}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "q"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?q=foo", 200, {"in": "router-decorator-depends"}), ( "/router-decorator-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-decorator-depends"}, ), ], ) def test_normal_app(url, status_code, expected): > response = client.get(url) tests/test_dependency_overrides.py:143: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_override_simple[/main-depends/-200-expected0] ______________ url = '/main-depends/', status_code = 200 expected = {'in': 'main-depends', 'params': {'limit': 10, 'q': None, 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_override_simple[/main-depends/?q=foo-200-expected1] ___________ url = '/main-depends/?q=foo', status_code = 200 expected = {'in': 'main-depends', 'params': {'limit': 10, 'q': 'foo', 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_override_simple[/main-depends/?q=foo&skip=100&limit=200-200-expected2] __ url = '/main-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'main-depends', 'params': {'limit': 10, 'q': 'foo', 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_override_simple[/decorator-depends/-200-expected3] ____________ url = '/decorator-depends/', status_code = 200 expected = {'in': 'decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_override_simple[/router-depends/-200-expected4] _____________ url = '/router-depends/', status_code = 200 expected = {'in': 'router-depends', 'params': {'limit': 10, 'q': None, 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_override_simple[/router-depends/?q=foo-200-expected5] __________ url = '/router-depends/?q=foo', status_code = 200 expected = {'in': 'router-depends', 'params': {'limit': 10, 'q': 'foo', 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_override_simple[/router-depends/?q=foo&skip=100&limit=200-200-expected6] _ url = '/router-depends/?q=foo&skip=100&limit=200', status_code = 200 expected = {'in': 'router-depends', 'params': {'limit': 10, 'q': 'foo', 'skip': 5}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_override_simple[/router-decorator-depends/-200-expected7] ________ url = '/router-decorator-depends/', status_code = 200 expected = {'in': 'router-decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 200, {"in": "main-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/main-depends/?q=foo&skip=100&limit=200", 200, {"in": "main-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/decorator-depends/", 200, {"in": "decorator-depends"}), ( "/router-depends/", 200, {"in": "router-depends", "params": {"q": None, "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ( "/router-depends/?q=foo&skip=100&limit=200", 200, {"in": "router-depends", "params": {"q": "foo", "skip": 5, "limit": 10}}, ), ("/router-decorator-depends/", 200, {"in": "router-decorator-depends"}), ], ) def test_override_simple(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_simple > response = client.get(url) tests/test_dependency_overrides.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_override_with_sub[/main-depends/-422-expected0] _____________ url = '/main-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_override_with_sub[/main-depends/?q=foo-422-expected1] __________ url = '/main-depends/?q=foo', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_override_with_sub[/main-depends/?k=bar-200-expected2] __________ url = '/main-depends/?k=bar', status_code = 200 expected = {'in': 'main-depends', 'params': {'k': 'bar'}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/main-depends/', query = 'k=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_override_with_sub[/decorator-depends/-422-expected3] ___________ url = '/decorator-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_override_with_sub[/decorator-depends/?q=foo-422-expected4] ________ url = '/decorator-depends/?q=foo', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_override_with_sub[/decorator-depends/?k=bar-200-expected5] ________ url = '/decorator-depends/?k=bar', status_code = 200 expected = {'in': 'decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/decorator-depends/' query = 'k=bar', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_override_with_sub[/router-depends/-422-expected6] ____________ url = '/router-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_override_with_sub[/router-depends/?q=foo-422-expected7] _________ url = '/router-depends/?q=foo', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_override_with_sub[/router-depends/?k=bar-200-expected8] _________ url = '/router-depends/?k=bar', status_code = 200 expected = {'in': 'router-depends', 'params': {'k': 'bar'}} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-depends/' query = 'k=bar', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_override_with_sub[/router-decorator-depends/-422-expected9] _______ url = '/router-decorator-depends/', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_override_with_sub[/router-decorator-depends/?q=foo-422-expected10] ____ url = '/router-decorator-depends/?q=foo', status_code = 422 expected = {'detail': [{'loc': ['query', 'k'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = 'q=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_override_with_sub[/router-decorator-depends/?k=bar-200-expected11] ____ url = '/router-decorator-depends/?k=bar', status_code = 200 expected = {'in': 'router-decorator-depends'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/main-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/main-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/main-depends/?k=bar", 200, {"in": "main-depends", "params": {"k": "bar"}}), ( "/decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/decorator-depends/?k=bar", 200, {"in": "decorator-depends"}), ( "/router-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-depends/?k=bar", 200, {"in": "router-depends", "params": {"k": "bar"}}, ), ( "/router-decorator-depends/", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ( "/router-decorator-depends/?q=foo", 422, { "detail": [ { "loc": ["query", "k"], "msg": "field required", "type": "value_error.missing", } ] }, ), ("/router-decorator-depends/?k=bar", 200, {"in": "router-decorator-depends"}), ], ) def test_override_with_sub(url, status_code, expected): app.dependency_overrides[common_parameters] = overrider_dependency_with_sub > response = client.get(url) tests/test_dependency_overrides.py:312: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/router-decorator-depends/' query = 'k=bar', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_normal __________________________________ def test_normal(): > response = client.get("/user") tests/test_dependency_security_overrides.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/user', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_override_data ______________________________ def test_override_data(): app.dependency_overrides[get_data] = get_data_override > response = client.get("/user") tests/test_dependency_security_overrides.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/user', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_override_security ____________________________ def test_override_security(): app.dependency_overrides[get_user] = get_user_override > response = client.get("/user") tests/test_dependency_security_overrides.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/user', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_deprecated_openapi_prefix.py:36: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_deprecated_openapi_prefix.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_duplicate_models_openapi.py:74: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_get_api_route ______________________________ def test_get_api_route(): > response = client.get("/") tests/test_duplicate_models_openapi.py:80: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_use_empty ________________________________ def test_use_empty(): > with client: tests/test_empty_router.py:22: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _________________________ test_override_http_exception _________________________ def test_override_http_exception(): > response = client.get("/http-exception") tests/test_exception_handlers.py:36: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/http-exception', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_override_request_validation_exception __________________ def test_override_request_validation_exception(): > response = client.get("/request-validation/invalid") tests/test_exception_handlers.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/request-validation/invalid' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_extra_routes.py:318: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_get_api_route ______________________________ def test_get_api_route(): > response = client.get("/items/foo") tests/test_extra_routes.py:324: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_get_api_route_not_decorated _______________________ def test_get_api_route_not_decorated(): > response = client.get("/items-not-decorated/foo") tests/test_extra_routes.py:330: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items-not-decorated/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_delete __________________________________ def test_delete(): > response = client.delete("/items/foo", json={"name": "Foo"}) tests/test_extra_routes.py:336: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:624: in delete return self.request('DELETE', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_head ___________________________________ def test_head(): > response = client.head("/items/foo") tests/test_extra_routes.py:342: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:577: in head return self.request('HEAD', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_options _________________________________ def test_options(): > response = client.options("/items/foo") tests/test_extra_routes.py:348: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:566: in options return self.request('OPTIONS', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_patch __________________________________ def test_patch(): > response = client.patch("/items/foo", json={"name": "Foo"}) tests/test_extra_routes.py:354: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:614: in patch return self.request('PATCH', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_trace __________________________________ def test_trace(): > response = client.request("trace", "/items/foo") tests/test_extra_routes.py:360: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_filter_pydantic_sub_model.py:131: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_filter_sub_model _____________________________ def test_filter_sub_model(): > response = client.get("/model/modelA") tests/test_filter_pydantic_sub_model.py:137: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/model/modelA', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_validator_is_cloned ___________________________ def test_validator_is_cloned(): with pytest.raises(ValidationError) as err: > client.get("/model/modelX") tests/test_filter_pydantic_sub_model.py:148: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/model/modelX', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_python_list_param_as_form ________________________ def test_python_list_param_as_form(): > response = client.post( "/form/python-list", data={"items": ["first", "second", "third"]} ) tests/test_forms_from_non_typing_sequences.py:26: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/form/python-list', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'36'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_python_set_param_as_form _________________________ def test_python_set_param_as_form(): > response = client.post( "/form/python-set", data={"items": ["first", "second", "third"]} ) tests/test_forms_from_non_typing_sequences.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/form/python-set', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'36'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_python_tuple_param_as_form ________________________ def test_python_tuple_param_as_form(): > response = client.post( "/form/python-tuple", data={"items": ["first", "second", "third"]} ) tests/test_forms_from_non_typing_sequences.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/form/python-tuple', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'36'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_get_request_body.py:100: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_get_with_body ______________________________ def test_get_with_body(): body = {"name": "Foo", "description": "Some description", "price": 5.5} > response = client.get("/product", json=body) tests/test_get_request_body.py:107: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/product', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'64'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_value_extracting_by_http _________________________ def test_value_extracting_by_http(): > response = client.get("/http") tests/test_http_connection_injection.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/http', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_value_extracting_by_ws __________________________ def test_value_extracting_by_ws(): > with client.websocket_connect("/ws") as websocket: tests/test_http_connection_injection.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _______________________________ test_sub_router ________________________________ def test_sub_router(): > response = client.get("/items/") tests/test_include_route.py:20: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): client = TestClient(app) > response = client.get("/openapi.json") tests/test_include_router_defaults_overrides.py:346: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_level1_override _____________________________ def test_level1_override(): > response = client.get("/override1?level1=foo") tests/test_include_router_defaults_overrides.py:351: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/override1' query = 'level1=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_level1_default ______________________________ def test_level1_default(): > response = client.get("/default1?level1=foo") tests/test_include_router_defaults_overrides.py:363: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/default1', query = 'level1=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_paths_level3[True-True-True] _______________________ override1 = True, override2 = True, override3 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/override3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_paths_level3[True-True-False] ______________________ override1 = False, override2 = True, override3 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/override3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_paths_level3[True-False-True] ______________________ override1 = True, override2 = False, override3 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/override3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_paths_level3[True-False-False] ______________________ override1 = False, override2 = False, override3 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/override3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_paths_level3[False-True-True] ______________________ override1 = True, override2 = True, override3 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/default3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_paths_level3[False-True-False] ______________________ override1 = False, override2 = True, override3 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/default3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_paths_level3[False-False-True] ______________________ override1 = True, override2 = False, override3 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/default3' query = 'level3=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_paths_level3[False-False-False] _____________________ override1 = False, override2 = False, override3 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) def test_paths_level3(override1, override2, override3): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/override3" content_type_level = "3" else: url += "/default3" url += "?level3=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:392: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/default3', query = 'level3=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[True-True-True-True-True] __________________ override1 = True, override2 = True, override3 = True, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/level1/level2/level3/level4/override5', query = 'level5=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[True-True-True-True-False] _________________ override1 = False, override2 = True, override3 = True, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level3/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[True-True-True-False-True] _________________ override1 = True, override2 = False, override3 = True, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level3/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-True-True-False-False] _________________ override1 = False, override2 = False, override3 = True, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level3/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[True-True-False-True-True] _________________ override1 = True, override2 = True, override3 = False, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-True-False-True-False] _________________ override1 = False, override2 = True, override3 = False, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-True-False-False-True] _________________ override1 = True, override2 = False, override3 = False, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-True-False-False-False] ________________ override1 = False, override2 = False, override3 = False, override4 = True override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level4/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[True-False-True-True-True] _________________ override1 = True, override2 = True, override3 = True, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/level3/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-True-True-False] _________________ override1 = False, override2 = True, override3 = True, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level3/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-True-False-True] _________________ override1 = True, override2 = False, override3 = True, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level3/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-True-False-False] ________________ override1 = False, override2 = False, override3 = True, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level3/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-False-True-True] _________________ override1 = True, override2 = True, override3 = False, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-False-True-False] ________________ override1 = False, override2 = True, override3 = False, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[True-False-False-False-True] ________________ override1 = True, override2 = False, override3 = False, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[True-False-False-False-False] ________________ override1 = False, override2 = False, override3 = False, override4 = False override5 = True @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/override5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_paths_level5[False-True-True-True-True] _________________ override1 = True, override2 = True, override3 = True, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/level1/level2/level3/level4/default5', query = 'level5=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-True-True-False] _________________ override1 = False, override2 = True, override3 = True, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level3/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-True-False-True] _________________ override1 = True, override2 = False, override3 = True, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level3/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-True-False-False] ________________ override1 = False, override2 = False, override3 = True, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level3/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-False-True-True] _________________ override1 = True, override2 = True, override3 = False, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-False-True-False] ________________ override1 = False, override2 = True, override3 = False, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-True-False-False-True] ________________ override1 = True, override2 = False, override3 = False, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[False-True-False-False-False] ________________ override1 = False, override2 = False, override3 = False, override4 = True override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level4/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-False-True-True-True] _________________ override1 = True, override2 = True, override3 = True, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/level3/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-False-True-True-False] ________________ override1 = False, override2 = True, override3 = True, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/level3/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-False-True-False-True] ________________ override1 = True, override2 = False, override3 = True, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level3/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[False-False-True-False-False] ________________ override1 = False, override2 = False, override3 = True, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level3/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_paths_level5[False-False-False-True-True] ________________ override1 = True, override2 = True, override3 = False, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/level2/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[False-False-False-True-False] ________________ override1 = False, override2 = True, override3 = False, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level2/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[False-False-False-False-True] ________________ override1 = True, override2 = False, override3 = False, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/level1/default5' query = 'level5=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_paths_level5[False-False-False-False-False] _______________ override1 = False, override2 = False, override3 = False, override4 = False override5 = False @pytest.mark.parametrize("override1", [True, False]) @pytest.mark.parametrize("override2", [True, False]) @pytest.mark.parametrize("override3", [True, False]) @pytest.mark.parametrize("override4", [True, False]) @pytest.mark.parametrize("override5", [True, False]) def test_paths_level5(override1, override2, override3, override4, override5): url = "" content_type_level = "0" if override1: url += "/level1" content_type_level = "1" if override2: url += "/level2" content_type_level = "2" if override3: url += "/level3" content_type_level = "3" if override4: url += "/level4" content_type_level = "4" if override5: url += "/override5" content_type_level = "5" else: url += "/default5" url += "?level5=foo" > response = client.get(url) tests/test_include_router_defaults_overrides.py:429: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/default5', query = 'level5=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_users ________________________________ def test_get_users(): """Check that /users returns expected data""" > response = client.get("/users") tests/test_infer_param_optionality.py:50: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_user _________________________________ def test_get_user(): """Check that /users/{user_id} returns expected data""" > response = client.get("/users/abc123") tests/test_infer_param_optionality.py:57: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/abc123', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_get_items_1 _______________________________ def test_get_items_1(): """Check that /items returns expected data""" > response = client.get("/items") tests/test_infer_param_optionality.py:64: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_get_items_2 _______________________________ def test_get_items_2(): """Check that /items returns expected data with user_id specified""" > response = client.get("/items?user_id=abc123") tests/test_infer_param_optionality.py:74: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items' query = 'user_id=abc123', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_get_item_1 ________________________________ def test_get_item_1(): """Check that /items/{item_id} returns expected data""" > response = client.get("/items/item01") tests/test_infer_param_optionality.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/item01', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_get_item_2 ________________________________ def test_get_item_2(): """Check that /items/{item_id} returns expected data with user_id specified""" > response = client.get("/items/item01?user_id=abc123") tests/test_infer_param_optionality.py:88: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/item01' query = 'user_id=abc123', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_users_items _____________________________ def test_get_users_items(): """Check that /users/{user_id}/items returns expected data""" > response = client.get("/users/abc123/items") tests/test_infer_param_optionality.py:95: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/abc123/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_users_item ______________________________ def test_get_users_item(): """Check that /users/{user_id}/items returns expected data""" > response = client.get("/users/abc123/items/item01") tests/test_infer_param_optionality.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/abc123/items/item01' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_schema_1 _________________________________ def test_schema_1(): """Check that the user_id is a required path parameter under /users""" > response = client.get("/openapi.json") tests/test_infer_param_optionality.py:109: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_schema_2 _________________________________ def test_schema_2(): """Check that the user_id is an optional query parameter under /items""" > response = client.get("/openapi.json") tests/test_infer_param_optionality.py:126: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_dt ____________________________________ def test_dt(): > with client: tests/test_inherited_custom_class.py:63: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_multi_body_errors.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_put_correct_body _____________________________ def test_put_correct_body(): > response = client.post("/items/", json=[{"name": "Foo", "age": 5}]) tests/test_multi_body_errors.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'27'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_jsonable_encoder_requiring_error _____________________ def test_jsonable_encoder_requiring_error(): > response = client.post("/items/", json=[{"name": "Foo", "age": -1.0}]) tests/test_multi_body_errors.py:153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'30'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_put_incorrect_body_multiple _______________________ def test_put_incorrect_body_multiple(): > response = client.post("/items/", json=[{"age": "five"}, {"age": "six"}]) tests/test_multi_body_errors.py:159: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'33'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_multi_query_errors.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_multi_query _______________________________ def test_multi_query(): > response = client.get("/items/?q=5&q=6") tests/test_multi_query_errors.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=5&q=6' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_multi_query_incorrect __________________________ def test_multi_query_incorrect(): > response = client.get("/items/?q=five&q=six") tests/test_multi_query_errors.py:116: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=five&q=six' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_swagger_ui ________________________________ def test_swagger_ui(): > response = client.get("/docs") tests/test_no_swagger_ui_redirect.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_swagger_ui_no_oauth2_redirect ______________________ def test_swagger_ui_no_oauth2_redirect(): > response = client.get("/docs/oauth2-redirect") tests/test_no_swagger_ui_redirect.py:25: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs/oauth2-redirect' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_response _________________________________ def test_response(): > response = client.get("/items/") tests/test_no_swagger_ui_redirect.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_servers _____________________________ def test_openapi_servers(): > response = client.get("/openapi.json") tests/test_openapi_servers.py:53: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_app ___________________________________ def test_app(): > response = client.get("/foo") tests/test_openapi_servers.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/foo', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_default_param_query_none _________________________ def test_default_param_query_none(): > response = client.get("/items/") tests/test_param_class.py:19: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_default_param_query ___________________________ def test_default_param_query(): > response = client.get("/items/?q=foo") tests/test_param_class.py:25: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_reused_param _______________________________ def test_reused_param(): > response = client.get("/openapi.json") tests/test_param_in_path_and_dependency.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_read_users ________________________________ def test_read_users(): > response = client.get("/users/42") tests/test_param_in_path_and_dependency.py:92: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_text_get _________________________________ def test_text_get(): > response = client.get("/text") tests/test_path.py:10: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/text', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_nonexistent _______________________________ def test_nonexistent(): > response = client.get("/nonexistent") tests/test_path.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/nonexistent', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/foobar-200-foobar] ____________________ path = '/path/foobar', expected_status = 200, expected_response = 'foobar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/foobar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/str/foobar-200-foobar] __________________ path = '/path/str/foobar', expected_status = 200, expected_response = 'foobar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/str/foobar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_get_path[/path/str/42-200-42] ______________________ path = '/path/str/42', expected_status = 200, expected_response = '42' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/str/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/str/True-200-True] ____________________ path = '/path/str/True', expected_status = 200, expected_response = 'True' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/str/True', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get_path[/path/int/foobar-422-expected_response4] ____________ path = '/path/int/foobar', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/int/foobar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/path/int/True-422-expected_response5] _____________ path = '/path/int/True', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/int/True', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_get_path[/path/int/42-200-42] ______________________ path = '/path/int/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/int/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/path/int/42.5-422-expected_response7] _____________ path = '/path/int/42.5', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/int/42.5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/float/foobar-422-expected_response8] ___________ path = '/path/float/foobar', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid float', 'type': 'type_error.float'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/float/foobar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get_path[/path/float/True-422-expected_response9] ____________ path = '/path/float/True', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid float', 'type': 'type_error.float'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/float/True', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_get_path[/path/float/42-200-42] _____________________ path = '/path/float/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/float/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/float/42.5-200-42.5] ___________________ path = '/path/float/42.5', expected_status = 200, expected_response = 42.5 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/float/42.5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/bool/foobar-422-expected_response12] ___________ path = '/path/bool/foobar', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value could not be parsed to a boolean', 'type': 'type_error.bool'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/foobar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/bool/True-200-True] ____________________ path = '/path/bool/True', expected_status = 200, expected_response = True @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/True', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/path/bool/42-422-expected_response14] _____________ path = '/path/bool/42', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value could not be parsed to a boolean', 'type': 'type_error.bool'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get_path[/path/bool/42.5-422-expected_response15] ____________ path = '/path/bool/42.5', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value could not be parsed to a boolean', 'type': 'type_error.bool'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/42.5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_get_path[/path/bool/1-200-True] _____________________ path = '/path/bool/1', expected_status = 200, expected_response = True @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/1', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/bool/0-200-False] _____________________ path = '/path/bool/0', expected_status = 200, expected_response = False @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/0', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/bool/true-200-True] ____________________ path = '/path/bool/true', expected_status = 200, expected_response = True @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/true', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/bool/False-200-False] ___________________ path = '/path/bool/False', expected_status = 200, expected_response = False @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/False', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/bool/false-200-False] ___________________ path = '/path/bool/false', expected_status = 200, expected_response = False @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/bool/false', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/param/foo-200-foo] ____________________ path = '/path/param/foo', expected_status = 200, expected_response = 'foo' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/path/param-required/foo-200-foo] ________________ path = '/path/param-required/foo', expected_status = 200 expected_response = 'foo' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-required/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/path/param-minlength/foo-200-foo] _______________ path = '/path/param-minlength/foo', expected_status = 200 expected_response = 'foo' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-minlength/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/path/param-minlength/fo-422-expected_response24] ________ path = '/path/param-minlength/fo', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value has at least 3 characters', 'type': 'value_error.any_str.min_length'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-minlength/fo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/path/param-maxlength/foo-200-foo] _______________ path = '/path/param-maxlength/foo', expected_status = 200 expected_response = 'foo' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-maxlength/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_get_path[/path/param-maxlength/foobar-422-expected_response26] ______ path = '/path/param-maxlength/foobar', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value has at most 3 characters', 'type': 'value_error.any_str.max_length'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-maxlength/foobar' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/path/param-min_maxlength/foo-200-foo] _____________ path = '/path/param-min_maxlength/foo', expected_status = 200 expected_response = 'foo' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-min_maxlength/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_get_path[/path/param-min_maxlength/foobar-422-expected_response28] ____ path = '/path/param-min_maxlength/foobar', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value has at most 3 characters', 'type': 'value_error.any_str.max_length'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/path/param-min_maxlength/foobar', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______ test_get_path[/path/param-min_maxlength/f-422-expected_response29] ______ path = '/path/param-min_maxlength/f', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 2}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value has at least 2 characters', 'type': 'value_error.any_str.min_length'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-min_maxlength/f' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-gt/42-200-42] ____________________ path = '/path/param-gt/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-gt/2-422-expected_response31] ____________ path = '/path/param-gt/2', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than 3', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-gt0/0.05-200-0.05] _________________ path = '/path/param-gt0/0.05', expected_status = 200, expected_response = 0.05 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt0/0.05' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-gt0/0-422-expected_response33] ___________ path = '/path/param-gt0/0', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 0}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than 0', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt0/0', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-ge/42-200-42] ____________________ path = '/path/param-ge/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/param-ge/3-200-3] _____________________ path = '/path/param-ge/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge/3', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-ge/2-422-expected_response36] ____________ path = '/path/param-ge/2', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than or equal to 3', 'type': 'value_error.number.not_ge'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-lt/42-422-expected_response37] ___________ path = '/path/param-lt/42', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than 3', 'type': 'value_error.number.not_lt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/param-lt/2-200-2] _____________________ path = '/path/param-lt/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-lt0/-1-200--1] ___________________ path = '/path/param-lt0/-1', expected_status = 200, expected_response = -1 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt0/-1', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-lt0/0-422-expected_response40] ___________ path = '/path/param-lt0/0', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 0}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than 0', 'type': 'value_error.number.not_lt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt0/0', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/path/param-le/42-422-expected_response41] ___________ path = '/path/param-le/42', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than or equal to 3', 'type': 'value_error.number.not_le'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le/42', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/param-le/3-200-3] _____________________ path = '/path/param-le/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le/3', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_get_path[/path/param-le/2-200-2] _____________________ path = '/path/param-le/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-lt-gt/2-200-2] ___________________ path = '/path/param-lt-gt/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/path/param-lt-gt/4-422-expected_response45] __________ path = '/path/param-lt-gt/4', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than 3', 'type': 'value_error.number.not_lt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt/4', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/path/param-lt-gt/0-422-expected_response46] __________ path = '/path/param-lt-gt/0', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 1}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than 1', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt/0', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-le-ge/2-200-2] ___________________ path = '/path/param-le-ge/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-le-ge/1-200-1] ___________________ path = '/path/param-le-ge/1', expected_status = 200, expected_response = 1 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge/1', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/path/param-le-ge/3-200-3] ___________________ path = '/path/param-le-ge/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge/3', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/path/param-le-ge/4-422-expected_response50] __________ path = '/path/param-le-ge/4', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than or equal to 3', 'type': 'value_error.number.not_le'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge/4', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/param-lt-int/2-200-2] ___________________ path = '/path/param-lt-int/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/path/param-lt-int/42-422-expected_response52] _________ path = '/path/param-lt-int/42', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than 3', 'type': 'value_error.number.not_lt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-int/42' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-lt-int/2.7-422-expected_response53] _________ path = '/path/param-lt-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-gt-int/42-200-42] __________________ path = '/path/param-gt-int/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt-int/42' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/path/param-gt-int/2-422-expected_response55] __________ path = '/path/param-gt-int/2', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than 3', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-gt-int/2.7-422-expected_response56] _________ path = '/path/param-gt-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-gt-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/path/param-le-int/42-422-expected_response57] _________ path = '/path/param-le-int/42', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than or equal to 3', 'type': 'value_error.number.not_le'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-int/42' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/param-le-int/3-200-3] ___________________ path = '/path/param-le-int/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-int/3' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/param-le-int/2-200-2] ___________________ path = '/path/param-le-int/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-le-int/2.7-422-expected_response60] _________ path = '/path/param-le-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-ge-int/42-200-42] __________________ path = '/path/param-ge-int/42', expected_status = 200, expected_response = 42 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge-int/42' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/path/param-ge-int/3-200-3] ___________________ path = '/path/param-ge-int/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge-int/3' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/path/param-ge-int/2-422-expected_response63] __________ path = '/path/param-ge-int/2', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than or equal to 3', 'type': 'value_error.number.not_ge'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-ge-int/2.7-422-expected_response64] _________ path = '/path/param-ge-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-ge-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-lt-gt-int/2-200-2] _________________ path = '/path/param-lt-gt-int/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-lt-gt-int/4-422-expected_response66] ________ path = '/path/param-lt-gt-int/4', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than 3', 'type': 'value_error.number.not_lt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt-int/4' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-lt-gt-int/0-422-expected_response67] ________ path = '/path/param-lt-gt-int/0', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 1}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is greater than 1', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt-int/0' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/path/param-lt-gt-int/2.7-422-expected_response68] _______ path = '/path/param-lt-gt-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-lt-gt-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-le-ge-int/2-200-2] _________________ path = '/path/param-le-ge-int/2', expected_status = 200, expected_response = 2 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge-int/2' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-le-ge-int/1-200-1] _________________ path = '/path/param-le-ge-int/1', expected_status = 200, expected_response = 1 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge-int/1' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/path/param-le-ge-int/3-200-3] _________________ path = '/path/param-le-ge-int/3', expected_status = 200, expected_response = 3 @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge-int/3' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/path/param-le-ge-int/4-422-expected_response72] ________ path = '/path/param-le-ge-int/4', expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 3}, 'loc': ['path', 'item_id'], 'msg': 'ensure this value is less than or equal to 3', 'type': 'value_error.number.not_le'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge-int/4' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/path/param-le-ge-int/2.7-422-expected_response73] _______ path = '/path/param-le-ge-int/2.7', expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/path/foobar", 200, "foobar"), ("/path/str/foobar", 200, "foobar"), ("/path/str/42", 200, "42"), ("/path/str/True", 200, "True"), ("/path/int/foobar", 422, response_not_valid_int), ("/path/int/True", 422, response_not_valid_int), ("/path/int/42", 200, 42), ("/path/int/42.5", 422, response_not_valid_int), ("/path/float/foobar", 422, response_not_valid_float), ("/path/float/True", 422, response_not_valid_float), ("/path/float/42", 200, 42), ("/path/float/42.5", 200, 42.5), ("/path/bool/foobar", 422, response_not_valid_bool), ("/path/bool/True", 200, True), ("/path/bool/42", 422, response_not_valid_bool), ("/path/bool/42.5", 422, response_not_valid_bool), ("/path/bool/1", 200, True), ("/path/bool/0", 200, False), ("/path/bool/true", 200, True), ("/path/bool/False", 200, False), ("/path/bool/false", 200, False), ("/path/param/foo", 200, "foo"), ("/path/param-required/foo", 200, "foo"), ("/path/param-minlength/foo", 200, "foo"), ("/path/param-minlength/fo", 422, response_at_least_3), ("/path/param-maxlength/foo", 200, "foo"), ("/path/param-maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/foo", 200, "foo"), ("/path/param-min_maxlength/foobar", 422, response_maximum_3), ("/path/param-min_maxlength/f", 422, response_at_least_2), ("/path/param-gt/42", 200, 42), ("/path/param-gt/2", 422, response_greater_than_3), ("/path/param-gt0/0.05", 200, 0.05), ("/path/param-gt0/0", 422, response_greater_than_0), ("/path/param-ge/42", 200, 42), ("/path/param-ge/3", 200, 3), ("/path/param-ge/2", 422, response_greater_than_equal_3), ("/path/param-lt/42", 422, response_less_than_3), ("/path/param-lt/2", 200, 2), ("/path/param-lt0/-1", 200, -1), ("/path/param-lt0/0", 422, response_less_than_0), ("/path/param-le/42", 422, response_less_than_equal_3), ("/path/param-le/3", 200, 3), ("/path/param-le/2", 200, 2), ("/path/param-lt-gt/2", 200, 2), ("/path/param-lt-gt/4", 422, response_less_than_3), ("/path/param-lt-gt/0", 422, response_greater_than_1), ("/path/param-le-ge/2", 200, 2), ("/path/param-le-ge/1", 200, 1), ("/path/param-le-ge/3", 200, 3), ("/path/param-le-ge/4", 422, response_less_than_equal_3), ("/path/param-lt-int/2", 200, 2), ("/path/param-lt-int/42", 422, response_less_than_3), ("/path/param-lt-int/2.7", 422, response_not_valid_int), ("/path/param-gt-int/42", 200, 42), ("/path/param-gt-int/2", 422, response_greater_than_3), ("/path/param-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-int/42", 422, response_less_than_equal_3), ("/path/param-le-int/3", 200, 3), ("/path/param-le-int/2", 200, 2), ("/path/param-le-int/2.7", 422, response_not_valid_int), ("/path/param-ge-int/42", 200, 42), ("/path/param-ge-int/3", 200, 3), ("/path/param-ge-int/2", 422, response_greater_than_equal_3), ("/path/param-ge-int/2.7", 422, response_not_valid_int), ("/path/param-lt-gt-int/2", 200, 2), ("/path/param-lt-gt-int/4", 422, response_less_than_3), ("/path/param-lt-gt-int/0", 422, response_greater_than_1), ("/path/param-lt-gt-int/2.7", 422, response_not_valid_int), ("/path/param-le-ge-int/2", 200, 2), ("/path/param-le-ge-int/1", 200, 1), ("/path/param-le-ge-int/3", 200, 3), ("/path/param-le-ge-int/4", 422, response_less_than_equal_3), ("/path/param-le-ge-int/2.7", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_path.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/param-le-ge-int/2.7' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_put_no_body.py:83: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_put_no_body _______________________________ def test_put_no_body(): > response = client.put("/items/foo") tests/test_put_no_body.py:89: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_put_no_body_with_body __________________________ def test_put_no_body_with_body(): > response = client.put("/items/foo", json={"name": "Foo"}) tests/test_put_no_body.py:95: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_path[/query-422-expected_response0] _________________ path = '/query', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/query?query=baz-200-foo bar baz] ________________ path = '/query?query=baz', expected_status = 200 expected_response = 'foo bar baz' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query', query = 'query=baz' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/query?not_declared=baz-422-expected_response2] _________ path = '/query?not_declared=baz', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query' query = 'not_declared=baz', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_path[/query/optional-200-foo bar] __________________ path = '/query/optional', expected_status = 200, expected_response = 'foo bar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/optional', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/query/optional?query=baz-200-foo bar baz] ___________ path = '/query/optional?query=baz', expected_status = 200 expected_response = 'foo bar baz' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/optional' query = 'query=baz', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/query/optional?not_declared=baz-200-foo bar] __________ path = '/query/optional?not_declared=baz', expected_status = 200 expected_response = 'foo bar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/optional' query = 'not_declared=baz', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/query/int-422-expected_response6] _______________ path = '/query/int', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_get_path[/query/int?query=42-200-foo bar 42] _______________ path = '/query/int?query=42', expected_status = 200 expected_response = 'foo bar 42' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int', query = 'query=42' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/query/int?query=42.5-422-expected_response8] __________ path = '/query/int?query=42.5', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int' query = 'query=42.5', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/query/int?query=baz-422-expected_response9] __________ path = '/query/int?query=baz', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int', query = 'query=baz' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______ test_get_path[/query/int?not_declared=baz-422-expected_response10] ______ path = '/query/int?not_declared=baz', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int' query = 'not_declared=baz', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_get_path[/query/int/optional-200-foo bar] ________________ path = '/query/int/optional', expected_status = 200 expected_response = 'foo bar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/optional', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/query/int/optional?query=50-200-foo bar 50] __________ path = '/query/int/optional?query=50', expected_status = 200 expected_response = 'foo bar 50' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/optional' query = 'query=50', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_get_path[/query/int/optional?query=foo-422-expected_response13] _____ path = '/query/int/optional?query=foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/optional' query = 'query=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_get_path[/query/int/default-200-foo bar 10] _______________ path = '/query/int/default', expected_status = 200 expected_response = 'foo bar 10' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/default', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/query/int/default?query=50-200-foo bar 50] ___________ path = '/query/int/default?query=50', expected_status = 200 expected_response = 'foo bar 50' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/default' query = 'query=50', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_get_path[/query/int/default?query=foo-422-expected_response16] ______ path = '/query/int/default?query=foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/int/default' query = 'query=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/query/param-200-foo bar] ____________________ path = '/query/param', expected_status = 200, expected_response = 'foo bar' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/query/param?query=50-200-foo bar 50] ______________ path = '/query/param?query=50', expected_status = 200 expected_response = 'foo bar 50' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param' query = 'query=50', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/query/param-required-422-expected_response19] _________ path = '/query/param-required', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param-required' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get_path[/query/param-required?query=50-200-foo bar 50] _________ path = '/query/param-required?query=50', expected_status = 200 expected_response = 'foo bar 50' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param-required' query = 'query=50', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/query/param-required/int-422-expected_response21] _______ path = '/query/param-required/int', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param-required/int' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/query/param-required/int?query=50-200-foo bar 50] _______ path = '/query/param-required/int?query=50', expected_status = 200 expected_response = 'foo bar 50' @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param-required/int' query = 'query=50', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __ test_get_path[/query/param-required/int?query=foo-422-expected_response23] __ path = '/query/param-required/int?query=foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'query'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/query", 422, response_missing), ("/query?query=baz", 200, "foo bar baz"), ("/query?not_declared=baz", 422, response_missing), ("/query/optional", 200, "foo bar"), ("/query/optional?query=baz", 200, "foo bar baz"), ("/query/optional?not_declared=baz", 200, "foo bar"), ("/query/int", 422, response_missing), ("/query/int?query=42", 200, "foo bar 42"), ("/query/int?query=42.5", 422, response_not_valid_int), ("/query/int?query=baz", 422, response_not_valid_int), ("/query/int?not_declared=baz", 422, response_missing), ("/query/int/optional", 200, "foo bar"), ("/query/int/optional?query=50", 200, "foo bar 50"), ("/query/int/optional?query=foo", 422, response_not_valid_int), ("/query/int/default", 200, "foo bar 10"), ("/query/int/default?query=50", 200, "foo bar 50"), ("/query/int/default?query=foo", 422, response_not_valid_int), ("/query/param", 200, "foo bar"), ("/query/param?query=50", 200, "foo bar 50"), ("/query/param-required", 422, response_missing), ("/query/param-required?query=50", 200, "foo bar 50"), ("/query/param-required/int", 422, response_missing), ("/query/param-required/int?query=50", 200, "foo bar 50"), ("/query/param-required/int?query=foo", 422, response_not_valid_int), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_query.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/query/param-required/int' query = 'query=foo', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_cookie_is_set_once ____________________________ def test_cookie_is_set_once(): > direct_response = client.get("/directCookie") tests/test_repeated_cookie_headers.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/directCookie', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_schema __________________________________ def test_schema(): > response = client.get("/openapi.json") tests/test_repeated_dependency_schema.py:90: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_response _________________________________ def test_response(): > response = client.get("/", headers={"someheader": "hello"}) tests/test_repeated_dependency_schema.py:100: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'someheader', b'hello')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_request_body_parameters_media_type.py:58: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________ test_dependency_set_status_code ________________________ def test_dependency_set_status_code(): > response = client.get("/") tests/test_response_change_status_code.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_response_class_no_mediatype.py:112: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_response_code_no_body.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_response_model_sub_types.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operations _____________________________ def test_path_operations(): > response = client.get("/valid1") tests/test_response_model_sub_types.py:153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/valid1', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_router_events ______________________________ def test_router_events(): assert state.app_startup is False assert state.router_startup is False assert state.sub_router_startup is False assert state.app_shutdown is False assert state.router_shutdown is False assert state.sub_router_shutdown is False > with TestClient(app) as client: tests/test_router_events.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/seg/users/foo") tests/test_router_prefix_with_template.py:21: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/seg/users/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_cookie.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me", cookies={"key": "secret"}) tests/test_security_api_key_cookie.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'cookie', b'key=secret')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_cookie.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_cookie_optional.py:61: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me", cookies={"key": "secret"}) tests/test_security_api_key_cookie_optional.py:67: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'cookie', b'key=secret')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_cookie_optional.py:73: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_header.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me", headers={"key": "secret"}) tests/test_security_api_key_header.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'key', b'secret')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_header.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_header_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me", headers={"key": "secret"}) tests/test_security_api_key_header_optional.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'key', b'secret')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_header_optional.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_query.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me?key=secret") tests/test_security_api_key_query.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = 'key=secret' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_query.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_api_key_query_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_security_api_key _____________________________ def test_security_api_key(): > response = client.get("/users/me?key=secret") tests/test_security_api_key_query_optional.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = 'key=secret' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_security_api_key_no_key _________________________ def test_security_api_key_no_key(): > response = client.get("/users/me") tests/test_security_api_key_query_optional.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_base.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_security_http_base ____________________________ def test_security_http_base(): > response = client.get("/users/me", headers={"Authorization": "Other foobar"}) tests/test_security_http_base.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_security_http_base_no_credentials ____________________ def test_security_http_base_no_credentials(): > response = client.get("/users/me") tests/test_security_http_base.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_base_optional.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_security_http_base ____________________________ def test_security_http_base(): > response = client.get("/users/me", headers={"Authorization": "Other foobar"}) tests/test_security_http_base_optional.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_security_http_base_no_credentials ____________________ def test_security_http_base_no_credentials(): > response = client.get("/users/me") tests/test_security_http_base_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_basic_optional.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_security_http_basic ___________________________ def test_security_http_basic(): auth = HTTPBasicAuth(username="john", password="secret") > response = client.get("/users/me", auth=auth) tests/test_security_http_basic_optional.py:55: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9objpzZWNyZXQ=')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_basic_no_credentials ____________________ def test_security_http_basic_no_credentials(): > response = client.get("/users/me") tests/test_security_http_basic_optional.py:61: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_security_http_basic_invalid_credentials _________________ def test_security_http_basic_invalid_credentials(): > response = client.get( "/users/me", headers={"Authorization": "Basic notabase64token"} ) tests/test_security_http_basic_optional.py:67: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic notabase64token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_http_basic_non_basic_credentials ________________ def test_security_http_basic_non_basic_credentials(): payload = b64encode(b"johnsecret").decode("ascii") auth_header = f"Basic {payload}" > response = client.get("/users/me", headers={"Authorization": auth_header}) tests/test_security_http_basic_optional.py:78: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9obnNlY3JldA==')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_basic_realm.py:45: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_security_http_basic ___________________________ def test_security_http_basic(): auth = HTTPBasicAuth(username="john", password="secret") > response = client.get("/users/me", auth=auth) tests/test_security_http_basic_realm.py:52: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9objpzZWNyZXQ=')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_basic_no_credentials ____________________ def test_security_http_basic_no_credentials(): > response = client.get("/users/me") tests/test_security_http_basic_realm.py:58: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_security_http_basic_invalid_credentials _________________ def test_security_http_basic_invalid_credentials(): > response = client.get( "/users/me", headers={"Authorization": "Basic notabase64token"} ) tests/test_security_http_basic_realm.py:65: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic notabase64token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_http_basic_non_basic_credentials ________________ def test_security_http_basic_non_basic_credentials(): payload = b64encode(b"johnsecret").decode("ascii") auth_header = f"Basic {payload}" > response = client.get("/users/me", headers={"Authorization": auth_header}) tests/test_security_http_basic_realm.py:76: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9obnNlY3JldA==')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_bearer.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_security_http_bearer ___________________________ def test_security_http_bearer(): > response = client.get("/users/me", headers={"Authorization": "Bearer foobar"}) tests/test_security_http_bearer.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_bearer_no_credentials ___________________ def test_security_http_bearer_no_credentials(): > response = client.get("/users/me") tests/test_security_http_bearer.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_security_http_bearer_incorrect_scheme_credentials ____________ def test_security_http_bearer_incorrect_scheme_credentials(): > response = client.get("/users/me", headers={"Authorization": "Basic notreally"}) tests/test_security_http_bearer.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic notreally')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_bearer_optional.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_security_http_bearer ___________________________ def test_security_http_bearer(): > response = client.get("/users/me", headers={"Authorization": "Bearer foobar"}) tests/test_security_http_bearer_optional.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_bearer_no_credentials ___________________ def test_security_http_bearer_no_credentials(): > response = client.get("/users/me") tests/test_security_http_bearer_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_security_http_bearer_incorrect_scheme_credentials ____________ def test_security_http_bearer_incorrect_scheme_credentials(): > response = client.get("/users/me", headers={"Authorization": "Basic notreally"}) tests/test_security_http_bearer_optional.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic notreally')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_digest.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_security_http_digest ___________________________ def test_security_http_digest(): > response = client.get("/users/me", headers={"Authorization": "Digest foobar"}) tests/test_security_http_digest.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Digest foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_digest_no_credentials ___________________ def test_security_http_digest_no_credentials(): > response = client.get("/users/me") tests/test_security_http_digest.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_security_http_digest_incorrect_scheme_credentials ____________ def test_security_http_digest_incorrect_scheme_credentials(): > response = client.get( "/users/me", headers={"Authorization": "Other invalidauthorization"} ) tests/test_security_http_digest.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other invalidauthorization')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_http_digest_optional.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_security_http_digest ___________________________ def test_security_http_digest(): > response = client.get("/users/me", headers={"Authorization": "Digest foobar"}) tests/test_security_http_digest_optional.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Digest foobar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_digest_no_credentials ___________________ def test_security_http_digest_no_credentials(): > response = client.get("/users/me") tests/test_security_http_digest_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_security_http_digest_incorrect_scheme_credentials ____________ def test_security_http_digest_incorrect_scheme_credentials(): > response = client.get( "/users/me", headers={"Authorization": "Other invalidauthorization"} ) tests/test_security_http_digest_optional.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other invalidauthorization')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_oauth2.py:157: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_security_oauth2 _____________________________ def test_security_oauth2(): > response = client.get("/users/me", headers={"Authorization": "Bearer footokenbar"}) tests/test_security_oauth2.py:163: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_security_oauth2_password_other_header __________________ def test_security_oauth2_password_other_header(): > response = client.get("/users/me", headers={"Authorization": "Other footokenbar"}) tests/test_security_oauth2.py:169: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_oauth2_password_bearer_no_header ________________ def test_security_oauth2_password_bearer_no_header(): > response = client.get("/users/me") tests/test_security_oauth2.py:175: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_strict_login[None-422-expected_response0] ________________ data = None, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'grant_type'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', ...'type': 'value_error.missing'}, {'loc': ['body', 'password'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data1-422-expected_response1] ________________ data = {'password': 'secret', 'username': 'johndoe'}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'grant_type'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'32'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data2-422-expected_response2] ________________ data = {'grant_type': 'incorrect', 'password': 'secret', 'username': 'johndoe'} expected_status = 422 expected_response = {'detail': [{'ctx': {'pattern': 'password'}, 'loc': ['body', 'grant_type'], 'msg': 'string does not match regex "password"', 'type': 'value_error.str.regex'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'53'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data3-200-expected_response3] ________________ data = {'grant_type': 'password', 'password': 'secret', 'username': 'johndoe'} expected_status = 200 expected_response = {'client_id': None, 'client_secret': None, 'grant_type': 'password', 'password': 'secret', ...} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2.py:247: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'52'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_oauth2_authorization_code_bearer.py:57: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_no_token _________________________________ def test_no_token(): > response = client.get("/items") tests/test_security_oauth2_authorization_code_bearer.py:63: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_incorrect_token _____________________________ def test_incorrect_token(): > response = client.get("/items", headers={"Authorization": "Non-existent testtoken"}) tests/test_security_oauth2_authorization_code_bearer.py:69: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Non-existent testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_token __________________________________ def test_token(): > response = client.get("/items", headers={"Authorization": "Bearer testtoken"}) tests/test_security_oauth2_authorization_code_bearer.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_oauth2_optional.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_security_oauth2 _____________________________ def test_security_oauth2(): > response = client.get("/users/me", headers={"Authorization": "Bearer footokenbar"}) tests/test_security_oauth2_optional.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_security_oauth2_password_other_header __________________ def test_security_oauth2_password_other_header(): > response = client.get("/users/me", headers={"Authorization": "Other footokenbar"}) tests/test_security_oauth2_optional.py:173: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_oauth2_password_bearer_no_header ________________ def test_security_oauth2_password_bearer_no_header(): > response = client.get("/users/me") tests/test_security_oauth2_optional.py:179: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_strict_login[None-422-expected_response0] ________________ data = None, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'grant_type'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', ...'type': 'value_error.missing'}, {'loc': ['body', 'password'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2_optional.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data1-422-expected_response1] ________________ data = {'password': 'secret', 'username': 'johndoe'}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'grant_type'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2_optional.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'32'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data2-422-expected_response2] ________________ data = {'grant_type': 'incorrect', 'password': 'secret', 'username': 'johndoe'} expected_status = 422 expected_response = {'detail': [{'ctx': {'pattern': 'password'}, 'loc': ['body', 'grant_type'], 'msg': 'string does not match regex "password"', 'type': 'value_error.str.regex'}]} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2_optional.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'53'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test_strict_login[data3-200-expected_response3] ________________ data = {'grant_type': 'password', 'password': 'secret', 'username': 'johndoe'} expected_status = 200 expected_response = {'client_id': None, 'client_secret': None, 'grant_type': 'password', 'password': 'secret', ...} @pytest.mark.parametrize( "data,expected_status,expected_response", [ (None, 422, required_params), ({"username": "johndoe", "password": "secret"}, 422, grant_type_required), ( {"username": "johndoe", "password": "secret", "grant_type": "incorrect"}, 422, grant_type_incorrect, ), ( {"username": "johndoe", "password": "secret", "grant_type": "password"}, 200, { "grant_type": "password", "username": "johndoe", "password": "secret", "scopes": [], "client_id": None, "client_secret": None, }, ), ], ) def test_strict_login(data, expected_status, expected_response): > response = client.post("/login", data=data) tests/test_security_oauth2_optional.py:251: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'52'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_oauth2_password_bearer_optional.py:51: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_no_token _________________________________ def test_no_token(): > response = client.get("/items") tests/test_security_oauth2_password_bearer_optional.py:57: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_token __________________________________ def test_token(): > response = client.get("/items", headers={"Authorization": "Bearer testtoken"}) tests/test_security_oauth2_password_bearer_optional.py:63: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_incorrect_token _____________________________ def test_incorrect_token(): > response = client.get("/items", headers={"Authorization": "Notexistent testtoken"}) tests/test_security_oauth2_password_bearer_optional.py:69: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Notexistent testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_openid_connect.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_security_oauth2 _____________________________ def test_security_oauth2(): > response = client.get("/users/me", headers={"Authorization": "Bearer footokenbar"}) tests/test_security_openid_connect.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_security_oauth2_password_other_header __________________ def test_security_oauth2_password_other_header(): > response = client.get("/users/me", headers={"Authorization": "Other footokenbar"}) tests/test_security_openid_connect.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_oauth2_password_bearer_no_header ________________ def test_security_oauth2_password_bearer_no_header(): > response = client.get("/users/me") tests/test_security_openid_connect.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_security_openid_connect_optional.py:60: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_security_oauth2 _____________________________ def test_security_oauth2(): > response = client.get("/users/me", headers={"Authorization": "Bearer footokenbar"}) tests/test_security_openid_connect_optional.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_security_oauth2_password_other_header __________________ def test_security_oauth2_password_other_header(): > response = client.get("/users/me", headers={"Authorization": "Other footokenbar"}) tests/test_security_openid_connect_optional.py:72: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Other footokenbar')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_oauth2_password_bearer_no_header ________________ def test_security_oauth2_password_bearer_no_header(): > response = client.get("/users/me") tests/test_security_openid_connect_optional.py:78: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_valid __________________________________ def test_valid(): > response = client.get("/items/valid") tests/test_serialize_response.py:39: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/valid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_coerce __________________________________ def test_coerce(): > response = client.get("/items/coerce") tests/test_serialize_response.py:45: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/coerce', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_validlist ________________________________ def test_validlist(): > response = client.get("/items/validlist") tests/test_serialize_response.py:51: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validlist', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_valid __________________________________ def test_valid(): > response = client.get("/items/valid") tests/test_serialize_response_dataclass.py:40: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/valid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_coerce __________________________________ def test_coerce(): > response = client.get("/items/coerce") tests/test_serialize_response_dataclass.py:46: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/coerce', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_validlist ________________________________ def test_validlist(): > response = client.get("/items/validlist") tests/test_serialize_response_dataclass.py:52: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validlist', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_valid __________________________________ def test_valid(): > response = client.get("/items/valid") tests/test_serialize_response_model.py:90: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/valid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_coerce __________________________________ def test_coerce(): > response = client.get("/items/coerce") tests/test_serialize_response_model.py:96: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/coerce', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_validlist ________________________________ def test_validlist(): > response = client.get("/items/validlist") tests/test_serialize_response_model.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validlist', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_validdict ________________________________ def test_validdict(): > response = client.get("/items/validdict") tests/test_serialize_response_model.py:116: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validdict', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_valid_exclude_unset ___________________________ def test_valid_exclude_unset(): > response = client.get("/items/valid-exclude-unset") tests/test_serialize_response_model.py:126: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/valid-exclude-unset' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_coerce_exclude_unset ___________________________ def test_coerce_exclude_unset(): > response = client.get("/items/coerce-exclude-unset") tests/test_serialize_response_model.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/coerce-exclude-unset' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_validlist_exclude_unset _________________________ def test_validlist_exclude_unset(): > response = client.get("/items/validlist-exclude-unset") tests/test_serialize_response_model.py:138: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validlist-exclude-unset' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_validdict_exclude_unset _________________________ def test_validdict_exclude_unset(): > response = client.get("/items/validdict-exclude-unset") tests/test_serialize_response_model.py:148: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/validdict-exclude-unset' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_return_defaults _____________________________ def test_return_defaults(): > response = client.get("/") tests/test_skip_defaults.py:74: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_return_exclude_unset ___________________________ def test_return_exclude_unset(): > response = client.get("/exclude_unset") tests/test_skip_defaults.py:79: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/exclude_unset', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_return_exclude_defaults _________________________ def test_return_exclude_defaults(): > response = client.get("/exclude_defaults") tests/test_skip_defaults.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/exclude_defaults', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_return_exclude_none ___________________________ def test_return_exclude_none(): > response = client.get("/exclude_none") tests/test_skip_defaults.py:89: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/exclude_none', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_return_exclude_unset_none ________________________ def test_return_exclude_unset_none(): > response = client.get("/exclude_unset_none") tests/test_skip_defaults.py:94: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/exclude_unset_none', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_starlette_exception.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_item _________________________________ def test_get_item(): > response = client.get("/items/foo") tests/test_starlette_exception.py:134: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_get_item_not_found ____________________________ def test_get_item_not_found(): > response = client.get("/items/bar") tests/test_starlette_exception.py:140: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_get_starlette_item ____________________________ def test_get_starlette_item(): > response = client.get("/starlette-items/foo") tests/test_starlette_exception.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/starlette-items/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_get_starlette_item_not_found _______________________ def test_get_starlette_item_not_found(): > response = client.get("/starlette-items/bar") tests/test_starlette_exception.py:153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/starlette-items/bar' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_route_converters_int ___________________________ def test_route_converters_int(): # Test integer conversion > response = client.get("/int/5") tests/test_starlette_urlconvertors.py:27: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/int/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_route_converters_float __________________________ def test_route_converters_float(): # Test float conversion > response = client.get("/float/25.5") tests/test_starlette_urlconvertors.py:35: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/float/25.5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_route_converters_path __________________________ def test_route_converters_path(): # Test path conversion > response = client.get("/path/some/example") tests/test_starlette_urlconvertors.py:43: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/path/some/example', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > with client: tests/test_sub_callbacks.py:271: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.post( "/invoices/", json={"id": "fooinvoice", "customer": "John", "total": 5.3} ) tests/test_sub_callbacks.py:278: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/invoices/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'54'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_swagger_ui ________________________________ def test_swagger_ui(): > response = client.get("/docs") tests/test_swagger_ui_init_oauth.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/docs', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_response _________________________________ def test_response(): > response = client.get("/items/") tests/test_swagger_ui_init_oauth.py:27: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_item_openapi_schema ___________________________ def test_item_openapi_schema(): > response = client.get("/openapi.json") tests/test_union_body.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_other_item _____________________________ def test_post_other_item(): > response = client.post("/items/", json={"price": 100}) tests/test_union_body.py:116: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'14'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_post_item ________________________________ def test_post_item(): > response = client.post("/items/", json={"name": "Foo"}) tests/test_union_body.py:122: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_inherited_item_openapi_schema ______________________ @skip_py36 def test_inherited_item_openapi_schema(): > response = client.get("/openapi.json") tests/test_union_inherited_body.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_post_extended_item ____________________________ @skip_py36 def test_post_extended_item(): > response = client.post("/items/", json={"name": "Foo", "age": 5}) tests/test_union_inherited_body.py:130: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'25'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_post_item ________________________________ @skip_py36 def test_post_item(): > response = client.post("/items/", json={"name": "Foo"}) tests/test_union_inherited_body.py:137: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_invalid _________________________________ def test_invalid(): with pytest.raises(ValidationError): > client.get("/items/invalid") tests/test_validate_response.py:41: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/invalid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_double_invalid ______________________________ def test_double_invalid(): with pytest.raises(ValidationError): > client.get("/items/innerinvalid") tests/test_validate_response.py:46: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/innerinvalid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_invalid_list _______________________________ def test_invalid_list(): with pytest.raises(ValidationError): > client.get("/items/invalidlist") tests/test_validate_response.py:51: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/invalidlist', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_invalid _________________________________ def test_invalid(): with pytest.raises(ValidationError): > client.get("/items/invalid") tests/test_validate_response_dataclass.py:43: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/invalid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_double_invalid ______________________________ def test_double_invalid(): with pytest.raises(ValidationError): > client.get("/items/innerinvalid") tests/test_validate_response_dataclass.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/innerinvalid', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_invalid_list _______________________________ def test_invalid_list(): with pytest.raises(ValidationError): > client.get("/items/invalidlist") tests/test_validate_response_dataclass.py:53: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/invalidlist', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_recursive ________________________________ def test_recursive(): > response = client.get("/items/recursive") tests/test_validate_response_recursive.py:58: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/recursive', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_app ___________________________________ def test_app(): client = TestClient(app) > with client.websocket_connect("/") as websocket: tests/test_ws_router.py:56: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _________________________________ test_router __________________________________ def test_router(): client = TestClient(app) > with client.websocket_connect("/router") as websocket: tests/test_ws_router.py:63: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError ______________________________ test_prefix_router ______________________________ def test_prefix_router(): client = TestClient(app) > with client.websocket_connect("/prefix/") as websocket: tests/test_ws_router.py:70: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _________________________________ test_router2 _________________________________ def test_router2(): client = TestClient(app) > with client.websocket_connect("/router2") as websocket: tests/test_ws_router.py:77: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError ____________________________ test_router_ws_depends ____________________________ def test_router_ws_depends(): client = TestClient(app) > with client.websocket_connect("/router-ws-depends/") as websocket: tests/test_ws_router.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _____________________ test_router_ws_depends_with_override _____________________ def test_router_ws_depends_with_override(): client = TestClient(app) app.dependency_overrides[ws_dependency] = lambda: "Override" > with client.websocket_connect("/router-ws-depends/") as websocket: tests/test_ws_router.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_modules_same_name_body/test_main.py:127: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_post_a __________________________________ def test_post_a(): data = {"a": 2, "b": "foo"} > response = client.post("/a/compute", json=data) tests/test_modules_same_name_body/test_main.py:134: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a/compute', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'20'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_a_invalid ______________________________ def test_post_a_invalid(): data = {"a": "bar", "b": "foo"} > response = client.post("/a/compute", json=data) tests/test_modules_same_name_body/test_main.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/a/compute', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'24'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_post_b __________________________________ def test_post_b(): data = {"a": 2, "b": "foo"} > response = client.post("/b/compute/", json=data) tests/test_modules_same_name_body/test_main.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/b/compute/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'20'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_b_invalid ______________________________ def test_post_b_invalid(): data = {"a": "bar", "b": "foo"} > response = client.post("/b/compute/", json=data) tests/test_modules_same_name_body/test_main.py:154: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/b/compute/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'24'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_additional_responses/test_tutorial001.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/items/foo") tests/test_tutorial/test_additional_responses/test_tutorial001.py:108: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_path_operation_not_found _________________________ def test_path_operation_not_found(): > response = client.get("/items/bar") tests/test_tutorial/test_additional_responses/test_tutorial001.py:114: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_additional_responses/test_tutorial002.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/items/foo") tests/test_tutorial/test_additional_responses/test_tutorial002.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_path_operation_img ____________________________ def test_path_operation_img(): shutil.copy("./docs/en/docs/img/favicon.png", "./image.png") > response = client.get("/items/foo?img=1") tests/test_tutorial/test_additional_responses/test_tutorial002.py:111: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = 'img=1' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_additional_responses/test_tutorial003.py:103: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/items/foo") tests/test_tutorial/test_additional_responses/test_tutorial003.py:109: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_path_operation_not_found _________________________ def test_path_operation_not_found(): > response = client.get("/items/bar") tests/test_tutorial/test_additional_responses/test_tutorial003.py:115: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_additional_responses/test_tutorial004.py:101: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/items/foo") tests/test_tutorial/test_additional_responses/test_tutorial004.py:107: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_path_operation_img ____________________________ def test_path_operation_img(): shutil.copy("./docs/en/docs/img/favicon.png", "./image.png") > response = client.get("/items/foo?img=1") tests/test_tutorial/test_additional_responses/test_tutorial004.py:114: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = 'img=1' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_update __________________________________ def test_update(): > response = client.put("/items/foo", json={"name": "Wrestlers"}) tests/test_tutorial/test_additional_status_codes/test_tutorial001.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'21'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_create __________________________________ def test_create(): > response = client.put("/items/red", json={"name": "Chillies"}) tests/test_tutorial/test_additional_status_codes/test_tutorial001.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/red', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'20'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_middleware ________________________________ def test_middleware(): client = TestClient(app, base_url="https://testserver") > response = client.get("/") tests/test_tutorial/test_advanced_middleware/test_tutorial001.py:8: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'https', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 443, host = 'testserver', port = 443 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_middleware ________________________________ def test_middleware(): client = TestClient(app, base_url="http://example.com") > response = client.get("/") tests/test_tutorial/test_advanced_middleware/test_tutorial002.py:8: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'example.com', path = '/', query = '', fragment = '' default_port = 80, host = 'example.com', port = 80 headers = [(b'host', b'example.com'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_middleware ________________________________ def test_middleware(): > response = client.get("/large", headers={"accept-encoding": "gzip"}) tests/test_tutorial/test_advanced_middleware/test_tutorial003.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/large', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > with TestClient(app) as client: tests/test_tutorial/test_async_sql_databases/test_tutorial001.py:114: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _______________________________ test_create_read _______________________________ def test_create_read(): > with TestClient(app) as client: tests/test_tutorial/test_async_sql_databases/test_tutorial001.py:121: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError __________________________________ test_root ___________________________________ @pytest.mark.asyncio async def test_root(): async with AsyncClient(app=app, base_url="http://test") as ac: > response = await ac.get("/") docs_src/async_tests/test_main.py:10: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/httpx/_client.py:1548: in get return await self.request( /usr/lib/python3/dist-packages/httpx/_client.py:1371: in request response = await self.send( /usr/lib/python3/dist-packages/httpx/_client.py:1406: in send response = await self._send_handling_auth( /usr/lib/python3/dist-packages/httpx/_client.py:1444: in _send_handling_auth response = await self._send_handling_redirects( /usr/lib/python3/dist-packages/httpx/_client.py:1476: in _send_handling_redirects response = await self._send_single_request(request, timeout) /usr/lib/python3/dist-packages/httpx/_client.py:1502: in _send_single_request (status_code, headers, stream, ext,) = await transport.arequest( _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , method = b'GET' url = (b'http', b'test', None, b'/') headers = [(b'Host', b'test'), (b'Accept', b'*/*'), (b'Accept-Encoding', b'gzip, deflate'), (b'Connection', b'keep-alive'), (b'User-Agent', b'python-httpx/0.16.1')] stream = ext = {'timeout': {'connect': 5.0, 'pool': 5.0, 'read': 5.0, 'write': 5.0}} async def arequest( self, method: bytes, url: Tuple[bytes, bytes, Optional[int], bytes], headers: List[Tuple[bytes, bytes]] = None, stream: httpcore.AsyncByteStream = None, ext: dict = None, ) -> Tuple[int, List[Tuple[bytes, bytes]], httpcore.AsyncByteStream, dict]: headers = [] if headers is None else headers stream = httpcore.PlainByteStream(content=b"") if stream is None else stream # ASGI scope. scheme, host, port, full_path = url path, _, query = full_path.partition(b"?") scope = { "type": "http", "asgi": {"version": "3.0"}, "http_version": "1.1", "method": method.decode(), "headers": [(k.lower(), v) for (k, v) in headers], "scheme": scheme.decode("ascii"), "path": unquote(path.decode("ascii")), "query_string": query, "server": (host.decode("ascii"), port), "client": self.client, "root_path": self.root_path, } # Request. request_body_chunks = stream.__aiter__() request_complete = False # Response. status_code = None response_headers = None body_parts = [] response_started = False response_complete = create_event() # ASGI callables. async def receive() -> dict: nonlocal request_complete if request_complete: await response_complete.wait() return {"type": "http.disconnect"} try: body = await request_body_chunks.__anext__() except StopAsyncIteration: request_complete = True return {"type": "http.request", "body": b"", "more_body": False} return {"type": "http.request", "body": body, "more_body": True} async def send(message: dict) -> None: nonlocal status_code, response_headers, response_started if message["type"] == "http.response.start": assert not response_started status_code = message["status"] response_headers = message.get("headers", []) response_started = True elif message["type"] == "http.response.body": assert not response_complete.is_set() body = message.get("body", b"") more_body = message.get("more_body", False) if body and method != b"HEAD": body_parts.append(body) if not more_body: response_complete.set() try: await self.app(scope, receive, send) except Exception: if self.raise_app_exceptions or not response_complete.is_set(): raise assert response_complete.is_set() assert status_code is not None assert response_headers is not None > stream = httpcore.PlainByteStream(content=b"".join(body_parts)) E AttributeError: module 'httpcore' has no attribute 'PlainByteStream' /usr/lib/python3/dist-packages/httpx/_transports/asgi.py:157: AttributeError ______________________________ test_async_testing ______________________________ @pytest.mark.asyncio async def test_async_testing(): > await test_root() tests/test_tutorial/test_async_tests/test_main.py:8: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/async_tests/test_main.py:10: in test_root response = await ac.get("/") /usr/lib/python3/dist-packages/httpx/_client.py:1548: in get return await self.request( /usr/lib/python3/dist-packages/httpx/_client.py:1371: in request response = await self.send( /usr/lib/python3/dist-packages/httpx/_client.py:1406: in send response = await self._send_handling_auth( /usr/lib/python3/dist-packages/httpx/_client.py:1444: in _send_handling_auth response = await self._send_handling_redirects( /usr/lib/python3/dist-packages/httpx/_client.py:1476: in _send_handling_redirects response = await self._send_single_request(request, timeout) /usr/lib/python3/dist-packages/httpx/_client.py:1502: in _send_single_request (status_code, headers, stream, ext,) = await transport.arequest( _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , method = b'GET' url = (b'http', b'test', None, b'/') headers = [(b'Host', b'test'), (b'Accept', b'*/*'), (b'Accept-Encoding', b'gzip, deflate'), (b'Connection', b'keep-alive'), (b'User-Agent', b'python-httpx/0.16.1')] stream = ext = {'timeout': {'connect': 5.0, 'pool': 5.0, 'read': 5.0, 'write': 5.0}} async def arequest( self, method: bytes, url: Tuple[bytes, bytes, Optional[int], bytes], headers: List[Tuple[bytes, bytes]] = None, stream: httpcore.AsyncByteStream = None, ext: dict = None, ) -> Tuple[int, List[Tuple[bytes, bytes]], httpcore.AsyncByteStream, dict]: headers = [] if headers is None else headers stream = httpcore.PlainByteStream(content=b"") if stream is None else stream # ASGI scope. scheme, host, port, full_path = url path, _, query = full_path.partition(b"?") scope = { "type": "http", "asgi": {"version": "3.0"}, "http_version": "1.1", "method": method.decode(), "headers": [(k.lower(), v) for (k, v) in headers], "scheme": scheme.decode("ascii"), "path": unquote(path.decode("ascii")), "query_string": query, "server": (host.decode("ascii"), port), "client": self.client, "root_path": self.root_path, } # Request. request_body_chunks = stream.__aiter__() request_complete = False # Response. status_code = None response_headers = None body_parts = [] response_started = False response_complete = create_event() # ASGI callables. async def receive() -> dict: nonlocal request_complete if request_complete: await response_complete.wait() return {"type": "http.disconnect"} try: body = await request_body_chunks.__anext__() except StopAsyncIteration: request_complete = True return {"type": "http.request", "body": b"", "more_body": False} return {"type": "http.request", "body": body, "more_body": True} async def send(message: dict) -> None: nonlocal status_code, response_headers, response_started if message["type"] == "http.response.start": assert not response_started status_code = message["status"] response_headers = message.get("headers", []) response_started = True elif message["type"] == "http.response.body": assert not response_complete.is_set() body = message.get("body", b"") more_body = message.get("more_body", False) if body and method != b"HEAD": body_parts.append(body) if not more_body: response_complete.set() try: await self.app(scope, receive, send) except Exception: if self.raise_app_exceptions or not response_complete.is_set(): raise assert response_complete.is_set() assert status_code is not None assert response_headers is not None > stream = httpcore.PlainByteStream(content=b"".join(body_parts)) E AttributeError: module 'httpcore' has no attribute 'PlainByteStream' /usr/lib/python3/dist-packages/httpx/_transports/asgi.py:157: AttributeError _____________________________________ test _____________________________________ def test(): log = Path("log.txt") if log.is_file(): os.remove(log) # pragma: no cover > response = client.post("/send-notification/foo@example.com") tests/test_tutorial/test_background_tasks/test_tutorial001.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/send-notification/foo@example.com', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________________ test _____________________________________ def test(): log = Path("log.txt") if log.is_file(): os.remove(log) # pragma: no cover > response = client.post("/send-notification/foo@example.com?q=some-query") tests/test_tutorial/test_background_tasks/test_tutorial002.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/send-notification/foo@example.com', query = 'q=some-query' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py:29: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py:35: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py:29: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py:35: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py:39: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_behind_a_proxy/test_tutorial004.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_tutorial/test_behind_a_proxy/test_tutorial004.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_get_path[/users?token=jessica-200-expected_response0-headers0] ______ path = '/users?token=jessica', expected_status = 200 expected_response = [{'username': 'Rick'}, {'username': 'Morty'}], headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users', query = 'token=jessica' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get_path[/users-422-expected_response1-headers1] _____________ path = '/users', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___ test_get_path[/users/foo?token=jessica-200-expected_response2-headers2] ____ path = '/users/foo?token=jessica', expected_status = 200 expected_response = {'username': 'foo'}, headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/foo' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_get_path[/users/foo-422-expected_response3-headers3] ___________ path = '/users/foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____ test_get_path[/users/me?token=jessica-200-expected_response4-headers4] ____ path = '/users/me?token=jessica', expected_status = 200 expected_response = {'username': 'fakecurrentuser'}, headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_get_path[/users/me-422-expected_response5-headers5] ___________ path = '/users/me', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_get_path[/items?token=jessica-200-expected_response6-headers6] ______ path = '/items?token=jessica', expected_status = 200 expected_response = {'gun': {'name': 'Portal Gun'}, 'plumbus': {'name': 'Plumbus'}} headers = {'X-Token': 'fake-super-secret-token'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'token=jessica' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get_path[/items-422-expected_response7-headers7] _____________ path = '/items', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {'X-Token': 'fake-super-secret-token'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_get_path[/items/plumbus?token=jessica-200-expected_response8-headers8] __ path = '/items/plumbus?token=jessica', expected_status = 200 expected_response = {'item_id': 'plumbus', 'name': 'Plumbus'} headers = {'X-Token': 'fake-super-secret-token'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/plumbus' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/items/plumbus-422-expected_response9-headers9] _________ path = '/items/plumbus', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {'X-Token': 'fake-super-secret-token'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/plumbus', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____ test_get_path[/items?token=jessica-400-expected_response10-headers10] _____ path = '/items?token=jessica', expected_status = 400 expected_response = {'detail': 'X-Token header invalid'} headers = {'X-Token': 'invalid'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'token=jessica' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __ test_get_path[/items/bar?token=jessica-400-expected_response11-headers11] ___ path = '/items/bar?token=jessica', expected_status = 400 expected_response = {'detail': 'X-Token header invalid'} headers = {'X-Token': 'invalid'} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____ test_get_path[/items?token=jessica-422-expected_response12-headers12] _____ path = '/items?token=jessica', expected_status = 422 expected_response = {'detail': [{'loc': ['header', 'x-token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'token=jessica' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_get_path[/items/plumbus?token=jessica-422-expected_response13-headers13] _ path = '/items/plumbus?token=jessica', expected_status = 422 expected_response = {'detail': [{'loc': ['header', 'x-token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/plumbus' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______ test_get_path[/?token=jessica-200-expected_response14-headers14] _______ path = '/?token=jessica', expected_status = 200 expected_response = {'message': 'Hello Bigger Applications!'}, headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = 'token=jessica' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_get_path[/-422-expected_response15-headers15] ______________ path = '/', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'token'], 'msg': 'field required', 'type': 'value_error.missing'}]} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get_path[/openapi.json-200-expected_response16-headers16] ________ path = '/openapi.json', expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type...n': 'Not found'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Update Item', ...}}, ...}} headers = {} @pytest.mark.parametrize( "path,expected_status,expected_response,headers", [ ( "/users?token=jessica", 200, [{"username": "Rick"}, {"username": "Morty"}], {}, ), ("/users", 422, no_jessica, {}), ("/users/foo?token=jessica", 200, {"username": "foo"}, {}), ("/users/foo", 422, no_jessica, {}), ("/users/me?token=jessica", 200, {"username": "fakecurrentuser"}, {}), ("/users/me", 422, no_jessica, {}), ( "/items?token=jessica", 200, {"plumbus": {"name": "Plumbus"}, "gun": {"name": "Portal Gun"}}, {"X-Token": "fake-super-secret-token"}, ), ("/items", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items/plumbus?token=jessica", 200, {"name": "Plumbus", "item_id": "plumbus"}, {"X-Token": "fake-super-secret-token"}, ), ("/items/plumbus", 422, no_jessica, {"X-Token": "fake-super-secret-token"}), ( "/items?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items/bar?token=jessica", 400, {"detail": "X-Token header invalid"}, {"X-Token": "invalid"}, ), ( "/items?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ( "/items/plumbus?token=jessica", 422, { "detail": [ { "loc": ["header", "x-token"], "msg": "field required", "type": "value_error.missing", } ] }, {}, ), ("/?token=jessica", 200, {"message": "Hello Bigger Applications!"}, {}), ("/", 422, no_jessica, {}), ("/openapi.json", 200, openapi_schema, {}), ], ) def test_get_path(path, expected_status, expected_response, headers): > response = client.get(path, headers=headers) tests/test_tutorial/test_bigger_applications/test_main.py:422: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_put_no_header ______________________________ def test_put_no_header(): > response = client.put("/items/foo") tests/test_tutorial/test_bigger_applications/test_main.py:428: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_put_invalid_header ____________________________ def test_put_invalid_header(): > response = client.put("/items/foo", headers={"X-Token": "invalid"}) tests/test_tutorial/test_bigger_applications/test_main.py:447: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_put ___________________________________ def test_put(): > response = client.put( "/items/plumbus?token=jessica", headers={"X-Token": "fake-super-secret-token"} ) tests/test_tutorial/test_bigger_applications/test_main.py:453: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/plumbus' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_put_forbidden ______________________________ def test_put_forbidden(): > response = client.put( "/items/bar?token=jessica", headers={"X-Token": "fake-super-secret-token"} ) tests/test_tutorial/test_bigger_applications/test_main.py:461: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_admin __________________________________ def test_admin(): > response = client.post( "/admin/?token=jessica", headers={"X-Token": "fake-super-secret-token"} ) tests/test_tutorial/test_bigger_applications/test_main.py:469: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/admin/' query = 'token=jessica', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_admin_invalid_header ___________________________ def test_admin_invalid_header(): > response = client.post("/admin/", headers={"X-Token": "invalid"}) tests/test_tutorial/test_bigger_applications/test_main.py:477: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/admin/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body/test_tutorial001.py:89: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body0-200-expected_response0] _____________ path = '/items/', body = {'name': 'Foo', 'price': 50.5}, expected_status = 200 expected_response = {'description': None, 'name': 'Foo', 'price': 50.5, 'tax': None} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'30'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body1-200-expected_response1] _____________ path = '/items/', body = {'name': 'Foo', 'price': '50.5'}, expected_status = 200 expected_response = {'description': None, 'name': 'Foo', 'price': 50.5, 'tax': None} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'32'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body2-200-expected_response2] _____________ path = '/items/' body = {'description': 'Some Foo', 'name': 'Foo', 'price': '50.5'} expected_status = 200 expected_response = {'description': 'Some Foo', 'name': 'Foo', 'price': 50.5, 'tax': None} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'59'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body3-200-expected_response3] _____________ path = '/items/' body = {'description': 'Some Foo', 'name': 'Foo', 'price': '50.5', 'tax': 0.3} expected_status = 200 expected_response = {'description': 'Some Foo', 'name': 'Foo', 'price': 50.5, 'tax': 0.3} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'71'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body4-422-expected_response4] _____________ path = '/items/', body = {'name': 'Foo'}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'price'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body5-422-expected_response5] _____________ path = '/items/', body = {'name': 'Foo', 'price': 'twenty'} expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'price'], 'msg': 'value is not a valid float', 'type': 'type_error.float'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'34'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-body6-422-expected_response6] _____________ path = '/items/', body = {}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'name'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', 'price'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'2'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/-None-422-expected_response7] ______________ path = '/items/', body = None, expected_status = 422 expected_response = {'detail': [{'loc': ['body'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/", {"name": "Foo", "price": 50.5}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5"}, 200, {"name": "Foo", "price": 50.5, "description": None, "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo"}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": None}, ), ( "/items/", {"name": "Foo", "price": "50.5", "description": "Some Foo", "tax": 0.3}, 200, {"name": "Foo", "price": 50.5, "description": "Some Foo", "tax": 0.3}, ), ("/items/", {"name": "Foo"}, 422, price_missing), ("/items/", {"name": "Foo", "price": "twenty"}, 422, price_not_float), ("/items/", {}, 422, name_price_missing), ("/items/", None, 422, body_missing), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.post(path, json=body) tests/test_tutorial/test_body/test_tutorial001.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_broken_body _____________________________ def test_post_broken_body(): > response = client.post("/items/", data={"name": "Foo", "price": 50.5}) tests/test_tutorial/test_body/test_tutorial001.py:176: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'19'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body_fields/test_tutorial001.py:113: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items/5-body0-200-expected_response0] __________________ path = '/items/5', body = {'item': {'name': 'Foo', 'price': 3.0}} expected_status = 200 expected_response = {'item': {'description': None, 'name': 'Foo', 'price': 3.0, 'tax': None}, 'item_id': 5} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", {"item": {"name": "Foo", "price": 3.0}}, 200, { "item_id": 5, "item": {"name": "Foo", "price": 3.0, "description": None, "tax": None}, }, ), ( "/items/6", { "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": "5.4", } }, 200, { "item_id": 6, "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": 5.4, }, }, ), ("/items/5", {"item": {"name": "Foo", "price": -3.0}}, 422, price_not_greater), ], ) def test(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_fields/test_tutorial001.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'39'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items/6-body1-200-expected_response1] __________________ path = '/items/6' body = {'item': {'description': 'Some bar', 'name': 'Bar', 'price': 0.2, 'tax': '5.4'}} expected_status = 200 expected_response = {'item': {'description': 'Some bar', 'name': 'Bar', 'price': 0.2, 'tax': 5.4}, 'item_id': 6} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", {"item": {"name": "Foo", "price": 3.0}}, 200, { "item_id": 5, "item": {"name": "Foo", "price": 3.0, "description": None, "tax": None}, }, ), ( "/items/6", { "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": "5.4", } }, 200, { "item_id": 6, "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": 5.4, }, }, ), ("/items/5", {"item": {"name": "Foo", "price": -3.0}}, 422, price_not_greater), ], ) def test(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_fields/test_tutorial001.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/6', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'80'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items/5-body2-422-expected_response2] __________________ path = '/items/5', body = {'item': {'name': 'Foo', 'price': -3.0}} expected_status = 422 expected_response = {'detail': [{'ctx': {'limit_value': 0}, 'loc': ['body', 'item', 'price'], 'msg': 'ensure this value is greater than 0', 'type': 'value_error.number.not_gt'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", {"item": {"name": "Foo", "price": 3.0}}, 200, { "item_id": 5, "item": {"name": "Foo", "price": 3.0, "description": None, "tax": None}, }, ), ( "/items/6", { "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": "5.4", } }, 200, { "item_id": 6, "item": { "name": "Bar", "price": 0.2, "description": "Some bar", "tax": 5.4, }, }, ), ("/items/5", {"item": {"name": "Foo", "price": -3.0}}, 422, price_not_greater), ], ) def test(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_fields/test_tutorial001.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'40'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body_multiple_params/test_tutorial001.py:105: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_post_body[/items/5?q=bar-body0-200-expected_response0] __________ path = '/items/5?q=bar', body = {'name': 'Foo', 'price': 50.5} expected_status = 200 expected_response = {'item': {'description': None, 'name': 'Foo', 'price': 50.5, 'tax': None}, 'item_id': 5, 'q': 'bar'} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5?q=bar", {"name": "Foo", "price": 50.5}, 200, { "item_id": 5, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "q": "bar", }, ), ("/items/5?q=bar", None, 200, {"item_id": 5, "q": "bar"}), ("/items/5", None, 200, {"item_id": 5}), ("/items/foo", None, 422, item_id_not_int), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial001.py:145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = 'q=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'30'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_post_body[/items/5?q=bar-None-200-expected_response1] __________ path = '/items/5?q=bar', body = None, expected_status = 200 expected_response = {'item_id': 5, 'q': 'bar'} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5?q=bar", {"name": "Foo", "price": 50.5}, 200, { "item_id": 5, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "q": "bar", }, ), ("/items/5?q=bar", None, 200, {"item_id": 5, "q": "bar"}), ("/items/5", None, 200, {"item_id": 5}), ("/items/foo", None, 422, item_id_not_int), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial001.py:145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = 'q=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/5-None-200-expected_response2] _____________ path = '/items/5', body = None, expected_status = 200 expected_response = {'item_id': 5} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5?q=bar", {"name": "Foo", "price": 50.5}, 200, { "item_id": 5, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "q": "bar", }, ), ("/items/5?q=bar", None, 200, {"item_id": 5, "q": "bar"}), ("/items/5", None, 200, {"item_id": 5}), ("/items/foo", None, 422, item_id_not_int), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial001.py:145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_post_body[/items/foo-None-422-expected_response3] ____________ path = '/items/foo', body = None, expected_status = 422 expected_response = {'detail': [{'loc': ['path', 'item_id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5?q=bar", {"name": "Foo", "price": 50.5}, 200, { "item_id": 5, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "q": "bar", }, ), ("/items/5?q=bar", None, 200, {"item_id": 5, "q": "bar"}), ("/items/5", None, 200, {"item_id": 5}), ("/items/foo", None, 422, item_id_not_int), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial001.py:145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body_multiple_params/test_tutorial003.py:116: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_post_body[/items/5-body0-200-expected_response0] _____________ path = '/items/5' body = {'importance': 2, 'item': {'name': 'Foo', 'price': 50.5}, 'user': {'username': 'Dave'}} expected_status = 200 expected_response = {'importance': 2, 'item': {'description': None, 'name': 'Foo', 'price': 50.5, 'tax': None}, 'item_id': 5, 'user': {'full_name': None, 'username': 'Dave'}} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", { "importance": 2, "item": {"name": "Foo", "price": 50.5}, "user": {"username": "Dave"}, }, 200, { "item_id": 5, "importance": 2, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "user": {"username": "Dave", "full_name": None}, }, ), ( "/items/5", None, 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ( "/items/5", [], 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial003.py:196: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'87'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_post_body[/items/5-None-422-expected_response1] _____________ path = '/items/5', body = None, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'item'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', 'user'...ype': 'value_error.missing'}, {'loc': ['body', 'importance'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", { "importance": 2, "item": {"name": "Foo", "price": 50.5}, "user": {"username": "Dave"}, }, 200, { "item_id": 5, "importance": 2, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "user": {"username": "Dave", "full_name": None}, }, ), ( "/items/5", None, 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ( "/items/5", [], 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial003.py:196: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_post_body[/items/5-body2-422-expected_response2] _____________ path = '/items/5', body = [], expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'item'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', 'user'...ype': 'value_error.missing'}, {'loc': ['body', 'importance'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/items/5", { "importance": 2, "item": {"name": "Foo", "price": 50.5}, "user": {"username": "Dave"}, }, 200, { "item_id": 5, "importance": 2, "item": { "name": "Foo", "price": 50.5, "description": None, "tax": None, }, "user": {"username": "Dave", "full_name": None}, }, ), ( "/items/5", None, 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ( "/items/5", [], 422, { "detail": [ { "loc": ["body", "item"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "user"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["body", "importance"], "msg": "field required", "type": "value_error.missing", }, ] }, ), ], ) def test_post_body(path, body, expected_status, expected_response): > response = client.put(path, json=body) tests/test_tutorial/test_body_multiple_params/test_tutorial003.py:196: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/5', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'2'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body_nested_models/test_tutorial009.py:79: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_post_body ________________________________ def test_post_body(): data = {"2": 2.2, "3": 3.3} > response = client.post("/index-weights/", json=data) tests/test_tutorial/test_body_nested_models/test_tutorial009.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/index-weights/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'20'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_invalid_body ____________________________ def test_post_invalid_body(): data = {"foo": 2.2, "3": 3.3} > response = client.post("/index-weights/", json=data) tests/test_tutorial/test_body_nested_models/test_tutorial009.py:93: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/index-weights/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'22'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_body_updates/test_tutorial001.py:135: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/baz") tests/test_tutorial/test_body_updates/test_tutorial001.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/baz', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_put ___________________________________ def test_put(): > response = client.put( "/items/bar", json={"name": "Barz", "price": 3, "description": None} ) tests/test_tutorial/test_body_updates/test_tutorial001.py:153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'49'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_default_openapi _____________________________ def test_default_openapi(): client = TestClient(tutorial001.app) > response = client.get("/openapi.json") tests/test_tutorial/test_conditional_openapi/test_tutorial001.py:29: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_disable_openapi _____________________________ monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f40b7f17f10> def test_disable_openapi(monkeypatch): monkeypatch.setenv("OPENAPI_URL", "") importlib.reload(tutorial001) client = TestClient(tutorial001.app) > response = client.get("/openapi.json") tests/test_tutorial/test_conditional_openapi/test_tutorial001.py:41: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test[/openapi.json-None-200-expected_response0] ________________ path = '/openapi.json', cookies = None, expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type...on': 'Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Read Items'}}}} @pytest.mark.parametrize( "path,cookies,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"ads_id": None}), ("/items", {"ads_id": "ads_track"}, 200, {"ads_id": "ads_track"}), ( "/items", {"ads_id": "ads_track", "session": "cookiesession"}, 200, {"ads_id": "ads_track"}, ), ("/items", {"session": "cookiesession"}, 200, {"ads_id": None}), ], ) def test(path, cookies, expected_status, expected_response): > response = client.get(path, cookies=cookies) tests/test_tutorial/test_cookie_params/test_tutorial001.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test[/items-None-200-expected_response1] ___________________ path = '/items', cookies = None, expected_status = 200 expected_response = {'ads_id': None} @pytest.mark.parametrize( "path,cookies,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"ads_id": None}), ("/items", {"ads_id": "ads_track"}, 200, {"ads_id": "ads_track"}), ( "/items", {"ads_id": "ads_track", "session": "cookiesession"}, 200, {"ads_id": "ads_track"}, ), ("/items", {"session": "cookiesession"}, 200, {"ads_id": None}), ], ) def test(path, cookies, expected_status, expected_response): > response = client.get(path, cookies=cookies) tests/test_tutorial/test_cookie_params/test_tutorial001.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items-cookies2-200-expected_response2] _________________ path = '/items', cookies = {'ads_id': 'ads_track'}, expected_status = 200 expected_response = {'ads_id': 'ads_track'} @pytest.mark.parametrize( "path,cookies,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"ads_id": None}), ("/items", {"ads_id": "ads_track"}, 200, {"ads_id": "ads_track"}), ( "/items", {"ads_id": "ads_track", "session": "cookiesession"}, 200, {"ads_id": "ads_track"}, ), ("/items", {"session": "cookiesession"}, 200, {"ads_id": None}), ], ) def test(path, cookies, expected_status, expected_response): > response = client.get(path, cookies=cookies) tests/test_tutorial/test_cookie_params/test_tutorial001.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'cookie', b'ads_id=ads_track')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items-cookies3-200-expected_response3] _________________ path = '/items', cookies = {'ads_id': 'ads_track', 'session': 'cookiesession'} expected_status = 200, expected_response = {'ads_id': 'ads_track'} @pytest.mark.parametrize( "path,cookies,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"ads_id": None}), ("/items", {"ads_id": "ads_track"}, 200, {"ads_id": "ads_track"}), ( "/items", {"ads_id": "ads_track", "session": "cookiesession"}, 200, {"ads_id": "ads_track"}, ), ("/items", {"session": "cookiesession"}, 200, {"ads_id": None}), ], ) def test(path, cookies, expected_status, expected_response): > response = client.get(path, cookies=cookies) tests/test_tutorial/test_cookie_params/test_tutorial001.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'cookie', b'ads_id=ads_track; session=cookiesession')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items-cookies4-200-expected_response4] _________________ path = '/items', cookies = {'session': 'cookiesession'}, expected_status = 200 expected_response = {'ads_id': None} @pytest.mark.parametrize( "path,cookies,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"ads_id": None}), ("/items", {"ads_id": "ads_track"}, 200, {"ads_id": "ads_track"}), ( "/items", {"ads_id": "ads_track", "session": "cookiesession"}, 200, {"ads_id": "ads_track"}, ), ("/items", {"session": "cookiesession"}, 200, {"ads_id": None}), ], ) def test(path, cookies, expected_status, expected_response): > response = client.get(path, cookies=cookies) tests/test_tutorial/test_cookie_params/test_tutorial001.py:91: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'cookie', b'session=cookiesession')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_cors ___________________________________ def test_cors(): client = TestClient(app) # Test pre-flight response headers = { "Origin": "https://localhost.tiangolo.com", "Access-Control-Request-Method": "GET", "Access-Control-Request-Headers": "X-Example", } > response = client.options("/", headers=headers) tests/test_tutorial/test_cors/test_tutorial001.py:14: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:566: in options return self.request('OPTIONS', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'origin', b'https://localhost.tiangolo.com'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_gzip_request[True] ____________________________ compress = True @pytest.mark.parametrize("compress", [True, False]) def test_gzip_request(compress): n = 1000 headers = {} body = [1] * n data = json.dumps(body).encode() if compress: data = gzip.compress(data) headers["Content-Encoding"] = "gzip" > response = client.post("/sum", data=data, headers=headers) tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sum', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-encoding', b'gzip'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_gzip_request[False] ___________________________ compress = False @pytest.mark.parametrize("compress", [True, False]) def test_gzip_request(compress): n = 1000 headers = {} body = [1] * n data = json.dumps(body).encode() if compress: data = gzip.compress(data) headers["Content-Encoding"] = "gzip" > response = client.post("/sum", data=data, headers=headers) tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/sum', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'3000')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_request_class ______________________________ def test_request_class(): > response = client.get("/check-class") tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/check-class', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_endpoint_works ______________________________ def test_endpoint_works(): > response = client.post("/", json=[1, 2, 3]) tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'9'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_exception_handler_body_access ______________________ def test_exception_handler_body_access(): > response = client.post("/", json={"numbers": [1, 2, 3]}) tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py:14: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'22'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/") tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_timed ________________________________ def test_get_timed(): > response = client.get("/timed") tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/timed', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_custom_response/test_tutorial001.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_custom_response/test_tutorial001b.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_custom_response/test_tutorial004.py:39: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_custom_response/test_tutorial005.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/") tests/test_tutorial/test_custom_response/test_tutorial005.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/typer", allow_redirects=False) tests/test_tutorial/test_custom_response/test_tutorial006.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/typer', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): fake_content = b"some fake video bytes" > response = client.get("/") tests/test_tutorial/test_custom_response/test_tutorial007.py:10: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ tmp_path = PosixPath('/tmp/pytest-of-buildd/pytest-1/test_get0') def test_get(tmp_path: Path): file_path: Path = tmp_path / "large-video-file.mp4" tutorial008.some_file_path = str(file_path) test_content = b"Fake video bytes" file_path.write_bytes(test_content) > response = client.get("/") tests/test_tutorial/test_custom_response/test_tutorial008.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_dependencies/test_tutorial001.py:130: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get[/items-200-expected_response0] ____________________ path = '/items', expected_status = 200 expected_response = {'limit': 100, 'q': None, 'skip': 0} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_get[/items?q=foo-200-expected_response1] _________________ path = '/items?q=foo', expected_status = 200 expected_response = {'limit': 100, 'q': 'foo', 'skip': 0} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get[/items?q=foo&skip=5-200-expected_response2] _____________ path = '/items?q=foo&skip=5', expected_status = 200 expected_response = {'limit': 100, 'q': 'foo', 'skip': 5} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'q=foo&skip=5' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________ test_get[/items?q=foo&skip=5&limit=30-200-expected_response3] _________ path = '/items?q=foo&skip=5&limit=30', expected_status = 200 expected_response = {'limit': 30, 'q': 'foo', 'skip': 5} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items' query = 'q=foo&skip=5&limit=30', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get[/users-200-expected_response4] ____________________ path = '/users', expected_status = 200 expected_response = {'limit': 100, 'q': None, 'skip': 0} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_get[/openapi.json-200-expected_response5] ________________ path = '/openapi.json', expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type...on': 'Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Read Users'}}}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items", 200, {"q": None, "skip": 0, "limit": 100}), ("/items?q=foo", 200, {"q": "foo", "skip": 0, "limit": 100}), ("/items?q=foo&skip=5", 200, {"q": "foo", "skip": 5, "limit": 100}), ("/items?q=foo&skip=5&limit=30", 200, {"q": "foo", "skip": 5, "limit": 30}), ("/users", 200, {"q": None, "skip": 0, "limit": 100}), ("/openapi.json", 200, openapi_schema), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_dependencies/test_tutorial004.py:88: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get[/items-200-expected_response0] ____________________ path = '/items', expected_status = 200 expected_response = {'items': [{'item_name': 'Foo'}, {'item_name': 'Bar'}, {'item_name': 'Baz'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_get[/items?q=foo-200-expected_response1] _________________ path = '/items?q=foo', expected_status = 200 expected_response = {'items': [{'item_name': 'Foo'}, {'item_name': 'Bar'}, {'item_name': 'Baz'}], 'q': 'foo'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get[/items?q=foo&skip=1-200-expected_response2] _____________ path = '/items?q=foo&skip=1', expected_status = 200 expected_response = {'items': [{'item_name': 'Bar'}, {'item_name': 'Baz'}], 'q': 'foo'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'q=foo&skip=1' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test_get[/items?q=bar&limit=2-200-expected_response3] _____________ path = '/items?q=bar&limit=2', expected_status = 200 expected_response = {'items': [{'item_name': 'Foo'}, {'item_name': 'Bar'}], 'q': 'bar'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = 'q=bar&limit=2' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get[/items?q=bar&skip=1&limit=1-200-expected_response4] _________ path = '/items?q=bar&skip=1&limit=1', expected_status = 200 expected_response = {'items': [{'item_name': 'Bar'}], 'q': 'bar'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items' query = 'q=bar&skip=1&limit=1', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________ test_get[/items?limit=1&q=bar&skip=1-200-expected_response5] _________ path = '/items?limit=1&q=bar&skip=1', expected_status = 200 expected_response = {'items': [{'item_name': 'Bar'}], 'q': 'bar'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ( "/items", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ] }, ), ( "/items?q=foo", 200, { "items": [ {"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}, ], "q": "foo", }, ), ( "/items?q=foo&skip=1", 200, {"items": [{"item_name": "Bar"}, {"item_name": "Baz"}], "q": "foo"}, ), ( "/items?q=bar&limit=2", 200, {"items": [{"item_name": "Foo"}, {"item_name": "Bar"}], "q": "bar"}, ), ( "/items?q=bar&skip=1&limit=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ( "/items?limit=1&q=bar&skip=1", 200, {"items": [{"item_name": "Bar"}], "q": "bar"}, ), ], ) def test_get(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_dependencies/test_tutorial004.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items' query = 'limit=1&q=bar&skip=1', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_dependencies/test_tutorial006.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_no_headers ______________________________ def test_get_no_headers(): > response = client.get("/items/") tests/test_tutorial/test_dependencies/test_tutorial006.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_get_invalid_one_header __________________________ def test_get_invalid_one_header(): > response = client.get("/items/", headers={"X-Token": "invalid"}) tests/test_tutorial/test_dependencies/test_tutorial006.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_get_invalid_second_header ________________________ def test_get_invalid_second_header(): > response = client.get( "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"} ) tests/test_tutorial/test_dependencies/test_tutorial006.py:112: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_get_valid_headers ____________________________ def test_get_valid_headers(): > response = client.get( "/items/", headers={ "X-Token": "fake-super-secret-token", "X-Key": "fake-super-secret-key", }, ) tests/test_tutorial/test_dependencies/test_tutorial006.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_dependencies/test_tutorial012.py:117: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get_no_headers_items ___________________________ def test_get_no_headers_items(): > response = client.get("/items/") tests/test_tutorial/test_dependencies/test_tutorial012.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get_no_headers_users ___________________________ def test_get_no_headers_users(): > response = client.get("/users/") tests/test_tutorial/test_dependencies/test_tutorial012.py:142: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_get_invalid_one_header_items _______________________ def test_get_invalid_one_header_items(): > response = client.get("/items/", headers={"X-Token": "invalid"}) tests/test_tutorial/test_dependencies/test_tutorial012.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get_invalid_one_users __________________________ def test_get_invalid_one_users(): > response = client.get("/users/", headers={"X-Token": "invalid"}) tests/test_tutorial/test_dependencies/test_tutorial012.py:167: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'invalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_get_invalid_second_header_items _____________________ def test_get_invalid_second_header_items(): > response = client.get( "/items/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"} ) tests/test_tutorial/test_dependencies/test_tutorial012.py:173: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________ test_get_invalid_second_header_users _____________________ def test_get_invalid_second_header_users(): > response = client.get( "/users/", headers={"X-Token": "fake-super-secret-token", "X-Key": "invalid"} ) tests/test_tutorial/test_dependencies/test_tutorial012.py:181: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_get_valid_headers_items _________________________ def test_get_valid_headers_items(): > response = client.get( "/items/", headers={ "X-Token": "fake-super-secret-token", "X-Key": "fake-super-secret-key", }, ) tests/test_tutorial/test_dependencies/test_tutorial012.py:189: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________ test_get_valid_headers_users _________________________ def test_get_valid_headers_users(): > response = client.get( "/users/", headers={ "X-Token": "fake-super-secret-token", "X-Key": "fake-super-secret-key", }, ) tests/test_tutorial/test_dependencies/test_tutorial012.py:201: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-token', b'fake-super-secret-token'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_events __________________________________ def test_events(): > with TestClient(app) as client: tests/test_tutorial/test_events/test_tutorial001.py:73: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _________________________________ test_events __________________________________ def test_events(): > with TestClient(app) as client: tests/test_tutorial/test_events/test_tutorial002.py:26: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_extending_openapi/test_tutorial001.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________________ test _____________________________________ def test(): > response = client.get("/items/") tests/test_tutorial/test_extending_openapi/test_tutorial001.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_extra_data_types/test_tutorial001.py:115: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_extra_types _______________________________ def test_extra_types(): item_id = "ff97dd87-a4a5-4a12-b412-cde99f33e00e" data = { "start_datetime": "2018-12-22T14:00:00+00:00", "end_datetime": "2018-12-24T15:00:00+00:00", "repeat_at": "15:30:00", "process_after": 300, } expected_response = data.copy() expected_response.update( { "start_process": "2018-12-22T14:05:00+00:00", "duration": 176_100, "item_id": item_id, } ) > response = client.put(f"/items/{item_id}", json=data) tests/test_tutorial/test_extra_data_types/test_tutorial001.py:136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver' path = '/items/ff97dd87-a4a5-4a12-b412-cde99f33e00e', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'139'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_extra_models/test_tutorial003.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_get_car _________________________________ def test_get_car(): > response = client.get("/items/item1") tests/test_tutorial/test_extra_models/test_tutorial003.py:110: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/item1', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_plane ________________________________ def test_get_plane(): > response = client.get("/items/item2") tests/test_tutorial/test_extra_models/test_tutorial003.py:119: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/item2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_extra_models/test_tutorial004.py:49: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_items ________________________________ def test_get_items(): > response = client.get("/items/") tests/test_tutorial/test_extra_models/test_tutorial004.py:55: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_extra_models/test_tutorial005.py:36: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_items ________________________________ def test_get_items(): > response = client.get("/keyword-weights/") tests/test_tutorial/test_extra_models/test_tutorial005.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/keyword-weights/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_get_path[/-200-expected_response0] ____________________ path = '/', expected_status = 200 expected_response = {'message': 'Hello World'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_first_steps/test_tutorial001.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test_get_path[/nonexistent-404-expected_response1] ______________ path = '/nonexistent', expected_status = 404 expected_response = {'detail': 'Not Found'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_first_steps/test_tutorial001.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/nonexistent', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________ test_get_path[/openapi.json-200-expected_response2] ______________ path = '/openapi.json', expected_status = 200 expected_response = {'info': {'title': 'FastAPI', 'version': '0.1.0'}, 'openapi': '3.0.2', 'paths': {'/': {'get': {'operationId': 'root__get', 'responses': {'200': {'content': {...}, 'description': 'Successful Response'}}, 'summary': 'Root'}}}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/", 200, {"message": "Hello World"}), ("/nonexistent", 404, {"detail": "Not Found"}), ("/openapi.json", 200, openapi_schema), ], ) def test_get_path(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_first_steps/test_tutorial001.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial001.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_item _________________________________ def test_get_item(): > response = client.get("/items/foo") tests/test_tutorial/test_handling_errors/test_tutorial001.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_get_item_not_found ____________________________ def test_get_item_not_found(): > response = client.get("/items/bar") tests/test_tutorial/test_handling_errors/test_tutorial001.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial002.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_item_header _____________________________ def test_get_item_header(): > response = client.get("/items-header/foo") tests/test_tutorial/test_handling_errors/test_tutorial002.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items-header/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_get_item_not_found_header ________________________ def test_get_item_not_found_header(): > response = client.get("/items-header/bar") tests/test_tutorial/test_handling_errors/test_tutorial002.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items-header/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial003.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/unicorns/shinny") tests/test_tutorial/test_handling_errors/test_tutorial003.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/unicorns/shinny', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_get_exception ______________________________ def test_get_exception(): > response = client.get("/unicorns/yolo") tests/test_tutorial/test_handling_errors/test_tutorial003.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/unicorns/yolo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial004.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get_validation_error ___________________________ def test_get_validation_error(): > response = client.get("/items/foo") tests/test_tutorial/test_handling_errors/test_tutorial004.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_http_error ______________________________ def test_get_http_error(): > response = client.get("/items/3") tests/test_tutorial/test_handling_errors/test_tutorial004.py:92: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/3', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/2") tests/test_tutorial/test_handling_errors/test_tutorial004.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial005.py:84: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_post_validation_error __________________________ def test_post_validation_error(): > response = client.post("/items/", json={"title": "towel", "size": "XL"}) tests/test_tutorial/test_handling_errors/test_tutorial005.py:90: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'32'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_post ___________________________________ def test_post(): data = {"title": "towel", "size": 5} > response = client.post("/items/", json=data) tests/test_tutorial/test_handling_errors/test_tutorial005.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'29'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_handling_errors/test_tutorial006.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get_validation_error ___________________________ def test_get_validation_error(): > response = client.get("/items/foo") tests/test_tutorial/test_handling_errors/test_tutorial006.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_get_http_error ______________________________ def test_get_http_error(): > response = client.get("/items/3") tests/test_tutorial/test_handling_errors/test_tutorial006.py:95: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/3', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/2") tests/test_tutorial/test_handling_errors/test_tutorial006.py:101: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/2', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________ test[/openapi.json-None-200-expected_response0] ________________ path = '/openapi.json', headers = None, expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type...on': 'Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Read Items'}}}} @pytest.mark.parametrize( "path,headers,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"User-Agent": "testclient"}), ("/items", {"X-Header": "notvalid"}, 200, {"User-Agent": "testclient"}), ("/items", {"User-Agent": "FastAPI test"}, 200, {"User-Agent": "FastAPI test"}), ], ) def test(path, headers, expected_status, expected_response): > response = client.get(path, headers=headers) tests/test_tutorial/test_header_params/test_tutorial001.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test[/items-None-200-expected_response1] ___________________ path = '/items', headers = None, expected_status = 200 expected_response = {'User-Agent': 'testclient'} @pytest.mark.parametrize( "path,headers,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"User-Agent": "testclient"}), ("/items", {"X-Header": "notvalid"}, 200, {"User-Agent": "testclient"}), ("/items", {"User-Agent": "FastAPI test"}, 200, {"User-Agent": "FastAPI test"}), ], ) def test(path, headers, expected_status, expected_response): > response = client.get(path, headers=headers) tests/test_tutorial/test_header_params/test_tutorial001.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items-headers2-200-expected_response2] _________________ path = '/items', headers = {'X-Header': 'notvalid'}, expected_status = 200 expected_response = {'User-Agent': 'testclient'} @pytest.mark.parametrize( "path,headers,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"User-Agent": "testclient"}), ("/items", {"X-Header": "notvalid"}, 200, {"User-Agent": "testclient"}), ("/items", {"User-Agent": "FastAPI test"}, 200, {"User-Agent": "FastAPI test"}), ], ) def test(path, headers, expected_status, expected_response): > response = client.get(path, headers=headers) tests/test_tutorial/test_header_params/test_tutorial001.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'x-header', b'notvalid')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test[/items-headers3-200-expected_response3] _________________ path = '/items', headers = {'User-Agent': 'FastAPI test'}, expected_status = 200 expected_response = {'User-Agent': 'FastAPI test'} @pytest.mark.parametrize( "path,headers,expected_status,expected_response", [ ("/openapi.json", None, 200, openapi_schema), ("/items", None, 200, {"User-Agent": "testclient"}), ("/items", {"X-Header": "notvalid"}, 200, {"User-Agent": "testclient"}), ("/items", {"User-Agent": "FastAPI test"}, 200, {"User-Agent": "FastAPI test"}), ], ) def test(path, headers, expected_status, expected_response): > response = client.get(path, headers=headers) tests/test_tutorial/test_header_params/test_tutorial001.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'FastAPI test'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_metadata/test_tutorial001.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_items __________________________________ def test_items(): > response = client.get("/items/") tests/test_tutorial/test_metadata/test_tutorial001.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_metadata/test_tutorial004.py:56: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operations _____________________________ def test_path_operations(): > response = client.get("/items/") tests/test_tutorial/test_metadata/test_tutorial004.py:62: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > with client: tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py:158: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.post( "/invoices/", json={"id": "fooinvoice", "customer": "John", "total": 5.3} ) tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py:165: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/invoices/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'54'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial001.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial001.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial002.py:28: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial002.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial003.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_get ___________________________________ def test_get(): > response = client.get("/items/") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial003.py:21: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_query_params_str_validations _______________________ def test_query_params_str_validations(): > response = client.post("/items/", json={"name": "Foo", "price": 42}) tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'28'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py:98: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_query_params_str_validations _______________________ def test_query_params_str_validations(): > response = client.post("/items/", json={"name": "Foo", "price": 42}) tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py:104: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'28'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py:57: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______ test_query_params_str_validations[/items/-200-expected_response0] _______ path = '/items/', expected_status = 200 expected_response = [{'name': 'Foo', 'price': 42}] @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items/", 200, [{"name": "Foo", "price": 42}]), ("/users/", 200, [{"username": "johndoe"}]), ("/elements/", 200, [{"item_id": "Foo"}]), ], ) def test_query_params_str_validations(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py:71: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______ test_query_params_str_validations[/users/-200-expected_response1] _______ path = '/users/', expected_status = 200 expected_response = [{'username': 'johndoe'}] @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items/", 200, [{"name": "Foo", "price": 42}]), ("/users/", 200, [{"username": "johndoe"}]), ("/elements/", 200, [{"item_id": "Foo"}]), ], ) def test_query_params_str_validations(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py:71: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_query_params_str_validations[/elements/-200-expected_response2] _____ path = '/elements/', expected_status = 200 expected_response = [{'item_id': 'Foo'}] @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/items/", 200, [{"name": "Foo", "price": 42}]), ("/users/", 200, [{"username": "johndoe"}]), ("/elements/", 200, [{"item_id": "Foo"}]), ], ) def test_query_params_str_validations(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py:71: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/elements/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_params/test_tutorial004.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_file_path ________________________________ def test_file_path(): > response = client.get("/files/home/johndoe/myfile.txt") tests/test_tutorial/test_path_params/test_tutorial004.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/home/johndoe/myfile.txt' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_root_file_path ______________________________ def test_root_file_path(): > response = client.get("/files//home/johndoe/myfile.txt") tests/test_tutorial/test_path_params/test_tutorial004.py:88: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files//home/johndoe/myfile.txt' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________________________ test_openapi _________________________________ def test_openapi(): > response = client.get("/openapi.json") tests/test_tutorial/test_path_params/test_tutorial005.py:153: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_get_enums[/models/alexnet-200-expected0] _________________ url = '/models/alexnet', status_code = 200 expected = {'message': 'Deep Learning FTW!', 'model_name': 'alexnet'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/models/alexnet", 200, {"model_name": "alexnet", "message": "Deep Learning FTW!"}, ), ( "/models/lenet", 200, {"model_name": "lenet", "message": "LeCNN all the images"}, ), ( "/models/resnet", 200, {"model_name": "resnet", "message": "Have some residuals"}, ), ( "/models/foo", 422, { "detail": [ { "ctx": {"enum_values": ["alexnet", "resnet", "lenet"]}, "loc": ["path", "model_name"], "msg": "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'", "type": "type_error.enum", } ] }, ), ], ) def test_get_enums(url, status_code, expected): > response = client.get(url) tests/test_tutorial/test_path_params/test_tutorial005.py:194: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/models/alexnet', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_enums[/models/lenet-200-expected1] __________________ url = '/models/lenet', status_code = 200 expected = {'message': 'LeCNN all the images', 'model_name': 'lenet'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/models/alexnet", 200, {"model_name": "alexnet", "message": "Deep Learning FTW!"}, ), ( "/models/lenet", 200, {"model_name": "lenet", "message": "LeCNN all the images"}, ), ( "/models/resnet", 200, {"model_name": "resnet", "message": "Have some residuals"}, ), ( "/models/foo", 422, { "detail": [ { "ctx": {"enum_values": ["alexnet", "resnet", "lenet"]}, "loc": ["path", "model_name"], "msg": "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'", "type": "type_error.enum", } ] }, ), ], ) def test_get_enums(url, status_code, expected): > response = client.get(url) tests/test_tutorial/test_path_params/test_tutorial005.py:194: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/models/lenet', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_get_enums[/models/resnet-200-expected2] _________________ url = '/models/resnet', status_code = 200 expected = {'message': 'Have some residuals', 'model_name': 'resnet'} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/models/alexnet", 200, {"model_name": "alexnet", "message": "Deep Learning FTW!"}, ), ( "/models/lenet", 200, {"model_name": "lenet", "message": "LeCNN all the images"}, ), ( "/models/resnet", 200, {"model_name": "resnet", "message": "Have some residuals"}, ), ( "/models/foo", 422, { "detail": [ { "ctx": {"enum_values": ["alexnet", "resnet", "lenet"]}, "loc": ["path", "model_name"], "msg": "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'", "type": "type_error.enum", } ] }, ), ], ) def test_get_enums(url, status_code, expected): > response = client.get(url) tests/test_tutorial/test_path_params/test_tutorial005.py:194: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/models/resnet', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test_get_enums[/models/foo-422-expected3] ___________________ url = '/models/foo', status_code = 422 expected = {'detail': [{'ctx': {'enum_values': ['alexnet', 'resnet', 'lenet']}, 'loc': ['path', 'model_name'], 'msg': "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'", 'type': 'type_error.enum'}]} @pytest.mark.parametrize( "url,status_code,expected", [ ( "/models/alexnet", 200, {"model_name": "alexnet", "message": "Deep Learning FTW!"}, ), ( "/models/lenet", 200, {"model_name": "lenet", "message": "LeCNN all the images"}, ), ( "/models/resnet", 200, {"model_name": "resnet", "message": "Have some residuals"}, ), ( "/models/foo", 422, { "detail": [ { "ctx": {"enum_values": ["alexnet", "resnet", "lenet"]}, "loc": ["path", "model_name"], "msg": "value is not a valid enumeration member; permitted: 'alexnet', 'resnet', 'lenet'", "type": "type_error.enum", } ] }, ), ], ) def test_get_enums(url, status_code, expected): > response = client.get(url) tests/test_tutorial/test_path_params/test_tutorial005.py:194: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/models/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test[/openapi.json-200-expected_response0] __________________ path = '/openapi.json', expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type... 'Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Read User Item'}}}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ("/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very"}), ("/items/foo", 422, query_required), ("/items/foo", 422, query_required), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial005.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test[/items/foo?needy=very-200-expected_response1] ______________ path = '/items/foo?needy=very', expected_status = 200 expected_response = {'item_id': 'foo', 'needy': 'very'} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ("/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very"}), ("/items/foo", 422, query_required), ("/items/foo", 422, query_required), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial005.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo' query = 'needy=very', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test[/items/foo-422-expected_response2] ____________________ path = '/items/foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'needy'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ("/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very"}), ("/items/foo", 422, query_required), ("/items/foo", 422, query_required), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial005.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test[/items/foo-422-expected_response3] ____________________ path = '/items/foo', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'needy'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ("/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very"}), ("/items/foo", 422, query_required), ("/items/foo", 422, query_required), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial005.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________ test[/openapi.json-200-expected_response0] __________________ path = '/openapi.json', expected_status = 200 expected_response = {'components': {'schemas': {'HTTPValidationError': {'properties': {'detail': {'items': {...}, 'title': 'Detail', 'type... 'Successful Response'}, '422': {'content': {...}, 'description': 'Validation Error'}}, 'summary': 'Read User Item'}}}} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ( "/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very", "skip": 0, "limit": None}, ), ( "/items/foo?skip=a&limit=b", 422, { "detail": [ { "loc": ["query", "needy"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["query", "skip"], "msg": "value is not a valid integer", "type": "type_error.integer", }, { "loc": ["query", "limit"], "msg": "value is not a valid integer", "type": "type_error.integer", }, ] }, ), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial006.py:139: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________ test[/items/foo?needy=very-200-expected_response1] ______________ path = '/items/foo?needy=very', expected_status = 200 expected_response = {'item_id': 'foo', 'limit': None, 'needy': 'very', 'skip': 0} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ( "/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very", "skip": 0, "limit": None}, ), ( "/items/foo?skip=a&limit=b", 422, { "detail": [ { "loc": ["query", "needy"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["query", "skip"], "msg": "value is not a valid integer", "type": "type_error.integer", }, { "loc": ["query", "limit"], "msg": "value is not a valid integer", "type": "type_error.integer", }, ] }, ), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial006.py:139: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo' query = 'needy=very', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________ test[/items/foo?skip=a&limit=b-422-expected_response2] ____________ path = '/items/foo?skip=a&limit=b', expected_status = 422 expected_response = {'detail': [{'loc': ['query', 'needy'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['query', 'sk...ype_error.integer'}, {'loc': ['query', 'limit'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer'}]} @pytest.mark.parametrize( "path,expected_status,expected_response", [ ("/openapi.json", 200, openapi_schema), ( "/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very", "skip": 0, "limit": None}, ), ( "/items/foo?skip=a&limit=b", 422, { "detail": [ { "loc": ["query", "needy"], "msg": "field required", "type": "value_error.missing", }, { "loc": ["query", "skip"], "msg": "value is not a valid integer", "type": "type_error.integer", }, { "loc": ["query", "limit"], "msg": "value is not a valid integer", "type": "type_error.integer", }, ] }, ), ], ) def test(path, expected_status, expected_response): > response = client.get(path) tests/test_tutorial/test_query_params/test_tutorial006.py:139: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo' query = 'skip=a&limit=b', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py:85: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____ test_query_params_str_validations[None-None-200-expected_response0] ______ q_name = None, q = None, expected_status = 200 expected_response = {'items': [{'item_id': 'Foo'}, {'item_id': 'Bar'}]} @pytest.mark.parametrize( "q_name,q,expected_status,expected_response", [ (None, None, 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ( "item-query", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}], "q": "fixedquery"}, ), ("q", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ("item-query", "nonregexquery", 422, regex_error), ], ) def test_query_params_str_validations(q_name, q, expected_status, expected_response): url = "/items/" if q_name and q: url = f"{url}?{q_name}={q}" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_query_params_str_validations[item-query-fixedquery-200-expected_response1] _ q_name = 'item-query', q = 'fixedquery', expected_status = 200 expected_response = {'items': [{'item_id': 'Foo'}, {'item_id': 'Bar'}], 'q': 'fixedquery'} @pytest.mark.parametrize( "q_name,q,expected_status,expected_response", [ (None, None, 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ( "item-query", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}], "q": "fixedquery"}, ), ("q", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ("item-query", "nonregexquery", 422, regex_error), ], ) def test_query_params_str_validations(q_name, q, expected_status, expected_response): url = "/items/" if q_name and q: url = f"{url}?{q_name}={q}" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'item-query=fixedquery', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____ test_query_params_str_validations[q-fixedquery-200-expected_response2] ____ q_name = 'q', q = 'fixedquery', expected_status = 200 expected_response = {'items': [{'item_id': 'Foo'}, {'item_id': 'Bar'}]} @pytest.mark.parametrize( "q_name,q,expected_status,expected_response", [ (None, None, 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ( "item-query", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}], "q": "fixedquery"}, ), ("q", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ("item-query", "nonregexquery", 422, regex_error), ], ) def test_query_params_str_validations(q_name, q, expected_status, expected_response): url = "/items/" if q_name and q: url = f"{url}?{q_name}={q}" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=fixedquery' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _ test_query_params_str_validations[item-query-nonregexquery-422-expected_response3] _ q_name = 'item-query', q = 'nonregexquery', expected_status = 422 expected_response = {'detail': [{'ctx': {'pattern': '^fixedquery$'}, 'loc': ['query', 'item-query'], 'msg': 'string does not match regex "^fixedquery$"', 'type': 'value_error.str.regex'}]} @pytest.mark.parametrize( "q_name,q,expected_status,expected_response", [ (None, None, 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ( "item-query", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}], "q": "fixedquery"}, ), ("q", "fixedquery", 200, {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}), ("item-query", "nonregexquery", 422, regex_error), ], ) def test_query_params_str_validations(q_name, q, expected_status, expected_response): url = "/items/" if q_name and q: url = f"{url}?{q_name}={q}" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py:120: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'item-query=nonregexquery', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py:79: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_multi_query_values ____________________________ def test_multi_query_values(): url = "/items/?q=foo&q=bar" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py:86: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=foo&q=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_query_no_values _____________________________ def test_query_no_values(): url = "/items/" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py:93: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py:80: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_default_query_values ___________________________ def test_default_query_values(): url = "/items/" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_multi_query_values ____________________________ def test_multi_query_values(): url = "/items/?q=baz&q=foobar" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py:94: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'q=baz&q=foobar', fragment = '', default_port = 80, host = 'testserver' port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py:80: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_multi_query_values ____________________________ def test_multi_query_values(): url = "/items/?q=foo&q=bar" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=foo&q=bar' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_query_no_values _____________________________ def test_query_no_values(): url = "/items/" > response = client.get(url) tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py:94: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_request_files/test_tutorial001.py:127: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_form_no_body ____________________________ def test_post_form_no_body(): > response = client.post("/files/") tests/test_tutorial/test_request_files/test_tutorial001.py:144: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_body_json ______________________________ def test_post_body_json(): > response = client.post("/files/", json={"file": "Foo"}) tests/test_tutorial/test_request_files/test_tutorial001.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_post_file ________________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-1/test_post_file0') def test_post_file(tmpdir): path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"") client = TestClient(app) > response = client.post("/files/", files={"file": open(path, "rb")}) tests/test_tutorial/test_request_files/test_tutorial001.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'158'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_large_file _____________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-1/test_post_large_file0') def test_post_large_file(tmpdir): default_pydantic_max_size = 2 ** 16 path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"x" * (default_pydantic_max_size + 1)) client = TestClient(app) > response = client.post("/files/", files={"file": open(path, "rb")}) tests/test_tutorial/test_request_files/test_tutorial001.py:173: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'65681'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_upload_file _____________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-1/test_post_upload_file0') def test_post_upload_file(tmpdir): path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"") client = TestClient(app) > response = client.post("/uploadfile/", files={"file": open(path, "rb")}) tests/test_tutorial/test_request_files/test_tutorial001.py:184: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/uploadfile/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'158'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_request_files/test_tutorial002.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_form_no_body ____________________________ def test_post_form_no_body(): > response = client.post("/files/") tests/test_tutorial/test_request_files/test_tutorial002.py:164: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_body_json ______________________________ def test_post_body_json(): > response = client.post("/files/", json={"file": "Foo"}) tests/test_tutorial/test_request_files/test_tutorial002.py:170: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_post_files ________________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-1/test_post_files0') def test_post_files(tmpdir): path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"") path2 = os.path.join(tmpdir, "test2.txt") with open(path2, "wb") as file: file.write(b"") client = TestClient(app) > response = client.post( "/files/", files=( ("files", ("test.txt", open(path, "rb"))), ("files", ("test2.txt", open(path2, "rb"))), ), ) tests/test_tutorial/test_request_files/test_tutorial002.py:184: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'282'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_upload_file _____________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-1/test_post_upload_file1') def test_post_upload_file(tmpdir): path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"") path2 = os.path.join(tmpdir, "test2.txt") with open(path2, "wb") as file: file.write(b"") client = TestClient(app) > response = client.post( "/uploadfiles/", files=( ("files", ("test.txt", open(path, "rb"))), ("files", ("test2.txt", open(path2, "rb"))), ), ) tests/test_tutorial/test_request_files/test_tutorial002.py:204: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/uploadfiles/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'282'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_get_root _________________________________ def test_get_root(): client = TestClient(app) > response = client.get("/") tests/test_tutorial/test_request_files/test_tutorial002.py:217: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_request_forms/test_tutorial001.py:87: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_post_body_form[/login/-body0-200-expected_response0] ___________ path = '/login/', body = {'password': 'secret', 'username': 'Foo'} expected_status = 200, expected_response = {'username': 'Foo'} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/login/", {"username": "Foo", "password": "secret"}, 200, {"username": "Foo"}, ), ("/login/", {"username": "Foo"}, 422, password_required), ("/login/", {"password": "secret"}, 422, username_required), ("/login/", None, 422, username_and_password_required), ], ) def test_post_body_form(path, body, expected_status, expected_response): > response = client.post(path, data=body) tests/test_tutorial/test_request_forms/test_tutorial001.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'28'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_post_body_form[/login/-body1-422-expected_response1] ___________ path = '/login/', body = {'username': 'Foo'}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'password'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/login/", {"username": "Foo", "password": "secret"}, 200, {"username": "Foo"}, ), ("/login/", {"username": "Foo"}, 422, password_required), ("/login/", {"password": "secret"}, 422, username_required), ("/login/", None, 422, username_and_password_required), ], ) def test_post_body_form(path, body, expected_status, expected_response): > response = client.post(path, data=body) tests/test_tutorial/test_request_forms/test_tutorial001.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'12'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________ test_post_body_form[/login/-body2-422-expected_response2] ___________ path = '/login/', body = {'password': 'secret'}, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'username'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/login/", {"username": "Foo", "password": "secret"}, 200, {"username": "Foo"}, ), ("/login/", {"username": "Foo"}, 422, password_required), ("/login/", {"password": "secret"}, 422, username_required), ("/login/", None, 422, username_and_password_required), ], ) def test_post_body_form(path, body, expected_status, expected_response): > response = client.post(path, data=body) tests/test_tutorial/test_request_forms/test_tutorial001.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'15'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________ test_post_body_form[/login/-None-422-expected_response3] ___________ path = '/login/', body = None, expected_status = 422 expected_response = {'detail': [{'loc': ['body', 'username'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', 'password'], 'msg': 'field required', 'type': 'value_error.missing'}]} @pytest.mark.parametrize( "path,body,expected_status,expected_response", [ ( "/login/", {"username": "Foo", "password": "secret"}, 200, {"username": "Foo"}, ), ("/login/", {"username": "Foo"}, 422, password_required), ("/login/", {"password": "secret"}, 422, username_required), ("/login/", None, 422, username_and_password_required), ], ) def test_post_body_form(path, body, expected_status, expected_response): > response = client.post(path, data=body) tests/test_tutorial/test_request_forms/test_tutorial001.py:141: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_body_json ______________________________ def test_post_body_json(): > response = client.post("/login/", json={"username": "Foo", "password": "secret"}) tests/test_tutorial/test_request_forms/test_tutorial001.py:147: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/login/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'41'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:90: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_form_no_body ____________________________ def test_post_form_no_body(): > response = client.post("/files/") tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:149: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_post_form_no_file ____________________________ def test_post_form_no_file(): > response = client.post("/files/", data={"token": "foo"}) tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:155: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'9'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_post_body_json ______________________________ def test_post_body_json(): > response = client.post("/files/", json={"file": "Foo", "token": "Bar"}) tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:161: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'31'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_post_file_no_token ____________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-1/test_post_file_no_token0') def test_post_file_no_token(tmpdir): path = os.path.join(tmpdir, "test.txt") with open(path, "wb") as file: file.write(b"") client = TestClient(app) > response = client.post("/files/", files={"file": open(path, "rb")}) tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:172: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'158'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_post_files_and_token ___________________________ tmpdir = local('/tmp/pytest-of-buildd/pytest-1/test_post_files_and_token0') def test_post_files_and_token(tmpdir): patha = Path(tmpdir) / "test.txt" pathb = Path(tmpdir) / "testb.txt" patha.write_text("") pathb.write_text("") client = TestClient(app) > response = client.post( "/files/", data={"token": "foo"}, files={ "file": patha.open("rb"), "fileb": ("testb.txt", pathb.open("rb"), "text/plain"), }, ) tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py:184: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/files/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'397'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.put("/get-or-create-task/foo") tests/test_tutorial/test_response_change_status_code/test_tutorial001.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:602: in put return self.request('PUT', url, data=data, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/get-or-create-task/foo' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.post("/cookie/") tests/test_tutorial/test_response_cookies/test_tutorial001.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/cookie/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.post("/cookie-and-object/") tests/test_tutorial/test_response_cookies/test_tutorial002.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/cookie-and-object/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'0')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/headers/") tests/test_tutorial/test_response_headers/test_tutorial001.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/headers/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_path_operation ______________________________ def test_path_operation(): > response = client.get("/headers-and-object/") tests/test_tutorial/test_response_headers/test_tutorial002.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/headers-and-object/' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_response_model/test_tutorial003.py:100: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_post_user ________________________________ def test_post_user(): > response = client.post( "/user/", json={ "username": "foo", "password": "fighter", "email": "foo@example.com", "full_name": "Grave Dohl", }, ) tests/test_tutorial/test_response_model/test_tutorial003.py:106: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/user/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'97'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_response_model/test_tutorial004.py:97: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get[/items/foo-data0] __________________________ url = '/items/foo', data = {'name': 'Foo', 'price': 50.2} @pytest.mark.parametrize( "url,data", [ ("/items/foo", {"name": "Foo", "price": 50.2}), ( "/items/bar", {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2}, ), ( "/items/baz", { "name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": [], }, ), ], ) def test_get(url, data): > response = client.get(url) tests/test_tutorial/test_response_model/test_tutorial004.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get[/items/bar-data1] __________________________ url = '/items/bar' data = {'description': 'The bartenders', 'name': 'Bar', 'price': 62, 'tax': 20.2} @pytest.mark.parametrize( "url,data", [ ("/items/foo", {"name": "Foo", "price": 50.2}), ( "/items/bar", {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2}, ), ( "/items/baz", { "name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": [], }, ), ], ) def test_get(url, data): > response = client.get(url) tests/test_tutorial/test_response_model/test_tutorial004.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_get[/items/baz-data2] __________________________ url = '/items/baz' data = {'description': None, 'name': 'Baz', 'price': 50.2, 'tags': [], ...} @pytest.mark.parametrize( "url,data", [ ("/items/foo", {"name": "Foo", "price": 50.2}), ( "/items/bar", {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2}, ), ( "/items/baz", { "name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": [], }, ), ], ) def test_get(url, data): > response = client.get(url) tests/test_tutorial/test_response_model/test_tutorial004.py:123: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/baz', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_response_model/test_tutorial005.py:124: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_read_item_name ______________________________ def test_read_item_name(): > response = client.get("/items/bar/name") tests/test_tutorial/test_response_model/test_tutorial005.py:130: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar/name', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_read_item_public_data __________________________ def test_read_item_public_data(): > response = client.get("/items/bar/public") tests/test_tutorial/test_response_model/test_tutorial005.py:136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar/public', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_response_model/test_tutorial006.py:124: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_read_item_name ______________________________ def test_read_item_name(): > response = client.get("/items/bar/name") tests/test_tutorial/test_response_model/test_tutorial006.py:130: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar/name', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_read_item_public_data __________________________ def test_read_item_public_data(): > response = client.get("/items/bar/public") tests/test_tutorial/test_response_model/test_tutorial006.py:136: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/bar/public', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_security/test_tutorial001.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_no_token _________________________________ def test_no_token(): > response = client.get("/items") tests/test_tutorial/test_security/test_tutorial001.py:43: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_token __________________________________ def test_token(): > response = client.get("/items", headers={"Authorization": "Bearer testtoken"}) tests/test_tutorial/test_security/test_tutorial001.py:50: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_incorrect_token _____________________________ def test_incorrect_token(): > response = client.get("/items", headers={"Authorization": "Notexistent testtoken"}) tests/test_tutorial/test_security/test_tutorial001.py:56: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Notexistent testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_security/test_tutorial003.py:113: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_login __________________________________ def test_login(): > response = client.post("/token", data={"username": "johndoe", "password": "secret"}) tests/test_tutorial/test_security/test_tutorial003.py:119: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/token', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'32'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_login_incorrect_password _________________________ def test_login_incorrect_password(): > response = client.post( "/token", data={"username": "johndoe", "password": "incorrect"} ) tests/test_tutorial/test_security/test_tutorial003.py:125: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/token', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'35'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_login_incorrect_username _________________________ def test_login_incorrect_username(): > response = client.post("/token", data={"username": "foo", "password": "secret"}) tests/test_tutorial/test_security/test_tutorial003.py:133: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/token', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'28'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_no_token _________________________________ def test_no_token(): > response = client.get("/users/me") tests/test_tutorial/test_security/test_tutorial003.py:139: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_token __________________________________ def test_token(): > response = client.get("/users/me", headers={"Authorization": "Bearer johndoe"}) tests/test_tutorial/test_security/test_tutorial003.py:146: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer johndoe')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_incorrect_token _____________________________ def test_incorrect_token(): > response = client.get("/users/me", headers={"Authorization": "Bearer nonexistent"}) tests/test_tutorial/test_security/test_tutorial003.py:158: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer nonexistent')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_incorrect_token_type ___________________________ def test_incorrect_token_type(): > response = client.get( "/users/me", headers={"Authorization": "Notexistent testtoken"} ) tests/test_tutorial/test_security/test_tutorial003.py:165: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Notexistent testtoken')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________________ test_inactive_user ______________________________ def test_inactive_user(): > response = client.get("/users/me", headers={"Authorization": "Bearer alice"}) tests/test_tutorial/test_security/test_tutorial003.py:174: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Bearer alice')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_security/test_tutorial006.py:35: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_security_http_basic ___________________________ def test_security_http_basic(): auth = HTTPBasicAuth(username="john", password="secret") > response = client.get("/users/me", auth=auth) tests/test_tutorial/test_security/test_tutorial006.py:42: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9objpzZWNyZXQ=')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________ test_security_http_basic_no_credentials ____________________ def test_security_http_basic_no_credentials(): > response = client.get("/users/me") tests/test_tutorial/test_security/test_tutorial006.py:48: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _________________ test_security_http_basic_invalid_credentials _________________ def test_security_http_basic_invalid_credentials(): > response = client.get( "/users/me", headers={"Authorization": "Basic notabase64token"} ) tests/test_tutorial/test_security/test_tutorial006.py:55: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic notabase64token')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________ test_security_http_basic_non_basic_credentials ________________ def test_security_http_basic_non_basic_credentials(): payload = b64encode(b"johnsecret").decode("ascii") auth_header = f"Basic {payload}" > response = client.get("/users/me", headers={"Authorization": auth_header}) tests/test_tutorial/test_security/test_tutorial006.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/me', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'authorization', b'Basic am9obnNlY3JldA==')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_setting_override _____________________________ def test_setting_override(): > test_main.test_app() tests/test_tutorial/test_settings/test_app02.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/settings/app02/test_main.py:17: in test_app response = client.get("/info") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/info', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_testing_dbs _______________________________ def test_testing_dbs(): test_db = Path("./test.db") if test_db.is_file(): # pragma: nocover test_db.unlink() # Import while creating the client to create the DB after starting the test session from docs_src.sql_databases.sql_app.tests import test_sql_app # Ensure import side effects are re-executed importlib.reload(test_sql_app) > test_sql_app.test_create_user() tests/test_tutorial/test_sql_databases/test_testing_databases.py:14: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/sql_databases/sql_app/tests/test_sql_app.py:33: in test_create_user response = client.post( /usr/lib/python3/dist-packages/requests/sessions.py:590: in post return self.request('POST', url, data=data, json=json, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive'), (b'content-length', b'66'), ...] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_openapi_schema_main ___________________________ def test_openapi_schema_main(): > response = client.get("/openapi.json") tests/test_tutorial/test_sub_applications/test_tutorial001.py:47: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/app") tests/test_tutorial/test_sub_applications/test_tutorial001.py:53: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/app', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________ test_openapi_schema_sub ____________________________ def test_openapi_schema_sub(): > response = client.get("/subapi/openapi.json") tests/test_tutorial/test_sub_applications/test_tutorial001.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/subapi/openapi.json' query = '', fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_sub ___________________________________ def test_sub(): > response = client.get("/subapi/sub") tests/test_tutorial/test_sub_applications/test_tutorial001.py:65: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/subapi/sub', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): if os.path.isdir("./static"): # pragma: nocover shutil.rmtree("./static") if os.path.isdir("./templates"): # pragma: nocover shutil.rmtree("./templates") shutil.copytree("./docs_src/templates/templates/", "./templates") shutil.copytree("./docs_src/templates/static/", "./static") from docs_src.templates.tutorial001 import app client = TestClient(app) > response = client.get("/items/foo") tests/test_tutorial/test_templates/test_tutorial001.py:17: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/foo', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_read_main ________________________________ def test_read_main(): > response = client.get("/") docs_src/app_testing/test_main.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_testing/test_main.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > test_read_main() tests/test_tutorial/test_testing/test_main.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/app_testing/test_main.py:9: in test_read_main response = client.get("/") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_read_main ________________________________ def test_read_main(): > response = client.get("/") docs_src/app_testing/tutorial001.py:16: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _____________________________ test_openapi_schema ______________________________ def test_openapi_schema(): > response = client.get("/openapi.json") tests/test_tutorial/test_testing/test_tutorial001.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/openapi.json', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > test_read_main() tests/test_tutorial/test_testing/test_tutorial001.py:30: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/app_testing/tutorial001.py:16: in test_read_main response = client.get("/") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_read_main ________________________________ def test_read_main(): client = TestClient(app) > response = client.get("/") docs_src/app_testing/tutorial002.py:22: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_websocket ________________________________ def test_websocket(): client = TestClient(app) > with client.websocket_connect("/ws") as websocket: docs_src/app_testing/tutorial002.py:29: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError __________________________________ test_main ___________________________________ def test_main(): > test_read_main() tests/test_tutorial/test_testing/test_tutorial002.py:5: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/app_testing/tutorial002.py:22: in test_read_main response = client.get("/") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_ws ____________________________________ def test_ws(): > test_websocket() tests/test_tutorial/test_testing/test_tutorial002.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/app_testing/tutorial002.py:29: in test_websocket with client.websocket_connect("/ws") as websocket: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _______________________________ test_read_items ________________________________ def test_read_items(): > with TestClient(app) as client: docs_src/app_testing/tutorial003.py:21: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError __________________________________ test_main ___________________________________ def test_main(): > test_read_items() tests/test_tutorial/test_testing/test_tutorial003.py:5: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/app_testing/tutorial003.py:21: in test_read_items with TestClient(app) as client: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( anyio.start_blocking_portal(**self.async_backend) ) @stack.callback def reset_portal() -> None: self.portal = None self.stream_send = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) self.stream_receive = StapledObjectStream( *anyio.create_memory_object_stream(math.inf) ) > self.task = portal.start_task_soon(self.lifespan) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:523: AttributeError ____________________________ test_override_in_items ____________________________ def test_override_in_items(): > response = client.get("/items/") docs_src/dependency_testing/tutorial001.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_override_in_items_with_q _________________________ def test_override_in_items_with_q(): > response = client.get("/items/?q=foo") docs_src/dependency_testing/tutorial001.py:43: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_override_in_items_with_params ______________________ def test_override_in_items_with_params(): > response = client.get("/items/?q=foo&skip=100&limit=200") docs_src/dependency_testing/tutorial001.py:52: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_override_in_items_run __________________________ def test_override_in_items_run(): > test_override_in_items() tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:11: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/dependency_testing/tutorial001.py:34: in test_override_in_items response = client.get("/items/") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_override_in_items_with_q_run _______________________ def test_override_in_items_with_q_run(): > test_override_in_items_with_q() tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/dependency_testing/tutorial001.py:43: in test_override_in_items_with_q response = client.get("/items/?q=foo") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________ test_override_in_items_with_params_run ____________________ def test_override_in_items_with_params_run(): > test_override_in_items_with_params() tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:19: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ docs_src/dependency_testing/tutorial001.py:52: in test_override_in_items_with_params response = client.get("/items/?q=foo&skip=100&limit=200") /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ____________________________ test_override_in_users ____________________________ def test_override_in_users(): > response = client.get("/users/") tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:23: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = '' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________ test_override_in_users_with_q _________________________ def test_override_in_users_with_q(): > response = client.get("/users/?q=foo") tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:32: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/', query = 'q=foo' fragment = '', default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ______________________ test_override_in_users_with_params ______________________ def test_override_in_users_with_params(): > response = client.get("/users/?q=foo&skip=100&limit=200") tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:41: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/users/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError _______________________________ test_normal_app ________________________________ def test_normal_app(): app.dependency_overrides = None > response = client.get("/items/?q=foo&skip=100&limit=200") tests/test_tutorial/test_testing_dependencies/test_tutorial001.py:51: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/items/' query = 'q=foo&skip=100&limit=200', fragment = '', default_port = 80 host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/") tests/test_tutorial/test_websockets/test_tutorial001.py:11: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ________________________________ test_websocket ________________________________ def test_websocket(): with pytest.raises(WebSocketDisconnect): > with client.websocket_connect("/ws") as websocket: tests/test_tutorial/test_websockets/test_tutorial001.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError __________________________________ test_main ___________________________________ def test_main(): > response = client.get("/") tests/test_tutorial/test_websockets/test_tutorial002.py:11: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError __________________________ test_websocket_with_cookie __________________________ def test_websocket_with_cookie(): with pytest.raises(WebSocketDisconnect): > with client.websocket_connect( "/items/foo/ws", cookies={"session": "fakesession"} ) as websocket: tests/test_tutorial/test_websockets/test_tutorial002.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError __________________________ test_websocket_with_header __________________________ def test_websocket_with_header(): with pytest.raises(WebSocketDisconnect): > with client.websocket_connect("/items/bar/ws?token=some-token") as websocket: tests/test_tutorial/test_websockets/test_tutorial002.py:37: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError _____________________ test_websocket_with_header_and_query _____________________ def test_websocket_with_header_and_query(): with pytest.raises(WebSocketDisconnect): > with client.websocket_connect("/items/2/ws?q=3&token=some-token") as websocket: tests/test_tutorial/test_websockets/test_tutorial002.py:54: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError ________________________ test_websocket_no_credentials _________________________ def test_websocket_no_credentials(): with pytest.raises(WebSocketDisconnect): > client.websocket_connect("/items/foo/ws") E Failed: DID NOT RAISE tests/test_tutorial/test_websockets/test_tutorial002.py:75: Failed _________________________ test_websocket_invalid_data __________________________ def test_websocket_invalid_data(): with pytest.raises(WebSocketDisconnect): > client.websocket_connect("/items/foo/ws?q=bar&token=some-token") E Failed: DID NOT RAISE tests/test_tutorial/test_websockets/test_tutorial002.py:80: Failed _____________________ test_websocket_handle_disconnection ______________________ def test_websocket_handle_disconnection(): > with client.websocket_connect("/ws/1234") as connection, client.websocket_connect( "/ws/5678" ) as connection_two: tests/test_tutorial/test_websockets/test_tutorial003.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = def __enter__(self) -> "WebSocketTestSession": self.exit_stack = contextlib.ExitStack() self.portal = self.exit_stack.enter_context(self.portal_factory()) try: > _: "Future[None]" = self.portal.start_task_soon(self._run) E AttributeError: 'BlockingPortal' object has no attribute 'start_task_soon' /usr/lib/python3/dist-packages/starlette/testclient.py:308: AttributeError __________________________________ test_flask __________________________________ def test_flask(): > response = client.get("/v1/") tests/test_tutorial/test_wsgi/test_tutorial001.py:9: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/v1/', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError ___________________________________ test_app ___________________________________ def test_app(): > response = client.get("/v2") tests/test_tutorial/test_wsgi/test_tutorial001.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /usr/lib/python3/dist-packages/requests/sessions.py:555: in get return self.request('GET', url, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:468: in request return super().request( /usr/lib/python3/dist-packages/requests/sessions.py:542: in request resp = self.send(prep, **send_kwargs) /usr/lib/python3/dist-packages/requests/sessions.py:655: in send r = adapter.send(request, **kwargs) /usr/lib/python3/dist-packages/starlette/testclient.py:266: in send raise exc _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = request = , args = () kwargs = {'cert': None, 'proxies': OrderedDict([('no', 'localhost'), ('https', 'https://127.0.0.1:9/'), ('http', 'http://127.0.0.1:9/')]), 'stream': False, 'timeout': None, ...} scheme = 'http', netloc = 'testserver', path = '/v2', query = '', fragment = '' default_port = 80, host = 'testserver', port = 80 headers = [(b'host', b'testserver'), (b'user-agent', b'testclient'), (b'accept-encoding', b'gzip, deflate'), (b'accept', b'*/*'), (b'connection', b'keep-alive')] def send( self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any ) -> requests.Response: scheme, netloc, path, query, fragment = ( str(item) for item in urlsplit(request.url) ) default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme] if ":" in netloc: host, port_string = netloc.split(":", 1) port = int(port_string) else: host = netloc port = default_port # Include the 'host' header. if "host" in request.headers: headers: typing.List[typing.Tuple[bytes, bytes]] = [] elif port == default_port: headers = [(b"host", host.encode())] else: headers = [(b"host", (f"{host}:{port}").encode())] # Include other request headers. headers += [ (key.lower().encode(), value.encode()) for key, value in request.headers.items() ] if scheme in {"ws", "wss"}: subprotocol = request.headers.get("sec-websocket-protocol", None) if subprotocol is None: subprotocols: typing.Sequence[str] = [] else: subprotocols = [value.strip() for value in subprotocol.split(",")] scope = { "type": "websocket", "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "subprotocols": subprotocols, } session = WebSocketTestSession(self.app, scope, self.portal_factory) raise _Upgrade(session) scope = { "type": "http", "http_version": "1.1", "method": request.method, "path": unquote(path), "root_path": self.root_path, "scheme": scheme, "query_string": query.encode(), "headers": headers, "client": ["testclient", 50000], "server": [host, port], "extensions": {"http.response.template": {}}, } request_complete = False response_started = False response_complete: anyio.Event raw_kwargs: typing.Dict[str, typing.Any] = {"body": io.BytesIO()} template = None context = None async def receive() -> Message: nonlocal request_complete if request_complete: if not response_complete.is_set(): await response_complete.wait() return {"type": "http.disconnect"} body = request.body if isinstance(body, str): body_bytes: bytes = body.encode("utf-8") elif body is None: body_bytes = b"" elif isinstance(body, types.GeneratorType): try: chunk = body.send(None) if isinstance(chunk, str): chunk = chunk.encode("utf-8") return {"type": "http.request", "body": chunk, "more_body": True} except StopIteration: request_complete = True return {"type": "http.request", "body": b""} else: body_bytes = body request_complete = True return {"type": "http.request", "body": body_bytes} async def send(message: Message) -> None: nonlocal raw_kwargs, response_started, template, context if message["type"] == "http.response.start": assert ( not response_started ), 'Received multiple "http.response.start" messages.' raw_kwargs["version"] = 11 raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ (key.decode(), value.decode()) for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse( raw_kwargs["headers"] ) response_started = True elif message["type"] == "http.response.body": assert ( response_started ), 'Received "http.response.body" without "http.response.start".' assert ( not response_complete.is_set() ), 'Received "http.response.body" after response completed.' body = message.get("body", b"") more_body = message.get("more_body", False) if request.method != "HEAD": raw_kwargs["body"].write(body) if not more_body: raw_kwargs["body"].seek(0) response_complete.set() elif message["type"] == "http.response.template": template = message["template"] context = message["context"] try: with self.portal_factory() as portal: > response_complete = portal.call(anyio.Event) E AttributeError: module 'anyio' has no attribute 'Event' /usr/lib/python3/dist-packages/starlette/testclient.py:262: AttributeError =========================== short test summary info ============================ FAILED tests/test_additional_properties.py::test_additional_properties_schema FAILED tests/test_additional_properties.py::test_additional_properties_post FAILED tests/test_additional_response_extra.py::test_openapi_schema - Attribu... FAILED tests/test_additional_response_extra.py::test_path_operation - Attribu... FAILED tests/test_additional_responses_bad.py::test_openapi_schema - Attribut... FAILED tests/test_additional_responses_custom_model_in_callback.py::test_openapi_schema FAILED tests/test_additional_responses_custom_validationerror.py::test_openapi_schema FAILED tests/test_additional_responses_default_validationerror.py::test_openapi_schema FAILED tests/test_additional_responses_response_class.py::test_openapi_schema FAILED tests/test_additional_responses_router.py::test_openapi_schema - Attri... FAILED tests/test_additional_responses_router.py::test_a - AttributeError: mo... FAILED tests/test_additional_responses_router.py::test_b - AttributeError: mo... FAILED tests/test_additional_responses_router.py::test_c - AttributeError: mo... FAILED tests/test_application.py::test_get_path[/api_route-200-expected_response0] FAILED tests/test_application.py::test_get_path[/non_decorated_route-200-expected_response1] FAILED tests/test_application.py::test_get_path[/nonexistent-404-expected_response2] FAILED tests/test_application.py::test_get_path[/openapi.json-200-expected_response3] FAILED tests/test_application.py::test_swagger_ui - AttributeError: module 'a... FAILED tests/test_application.py::test_swagger_ui_oauth2_redirect - Attribute... FAILED tests/test_application.py::test_redoc - AttributeError: module 'anyio'... FAILED tests/test_application.py::test_enum_status_code_response - AttributeE... FAILED tests/test_callable_endpoint.py::test_partial - AttributeError: module... FAILED tests/test_custom_route_class.py::test_get_path[/a-200-expected_response0] FAILED tests/test_custom_route_class.py::test_get_path[/a/b-200-expected_response1] FAILED tests/test_custom_route_class.py::test_get_path[/a/b/c-200-expected_response2] FAILED tests/test_custom_route_class.py::test_get_path[/openapi.json-200-expected_response3] FAILED tests/test_custom_swagger_ui_redirect.py::test_swagger_ui - AttributeE... FAILED tests/test_custom_swagger_ui_redirect.py::test_swagger_ui_oauth2_redirect FAILED tests/test_custom_swagger_ui_redirect.py::test_response - AttributeErr... FAILED tests/test_datetime_custom_encoder.py::test_dt - AttributeError: 'Bloc... FAILED tests/test_default_response_class_router.py::test_app - AttributeError... FAILED tests/test_default_response_class_router.py::test_app_override - Attri... FAILED tests/test_default_response_class_router.py::test_router_a - Attribute... FAILED tests/test_default_response_class_router.py::test_router_a_override - ... FAILED tests/test_default_response_class_router.py::test_router_a_a - Attribu... FAILED tests/test_default_response_class_router.py::test_router_a_a_override FAILED tests/test_default_response_class_router.py::test_router_a_b - Attribu... FAILED tests/test_default_response_class_router.py::test_router_a_b_override FAILED tests/test_default_response_class_router.py::test_router_b - Attribute... FAILED tests/test_default_response_class_router.py::test_router_b_override - ... FAILED tests/test_default_response_class_router.py::test_router_b_a - Attribu... FAILED tests/test_default_response_class_router.py::test_router_b_a_override FAILED tests/test_default_response_class_router.py::test_router_b_a_c - Attri... FAILED tests/test_default_response_class_router.py::test_router_b_a_c_override FAILED tests/test_dependency_cache.py::test_normal_counter - AttributeError: ... FAILED tests/test_dependency_cache.py::test_sub_counter - AttributeError: mod... FAILED tests/test_dependency_cache.py::test_sub_counter_no_cache - AttributeE... FAILED tests/test_dependency_class.py::test_class_dependency[/callable-dependency-callable-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/callable-gen-dependency-callable-gen-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/async-callable-dependency-async-callable-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/async-callable-gen-dependency-async-callable-gen-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/synchronous-method-dependency-synchronous-method-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/synchronous-method-gen-dependency-synchronous-method-gen-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/asynchronous-method-dependency-asynchronous-method-dependency] FAILED tests/test_dependency_class.py::test_class_dependency[/asynchronous-method-gen-dependency-asynchronous-method-gen-dependency] FAILED tests/test_dependency_contextmanager.py::test_async_state - AttributeE... FAILED tests/test_dependency_contextmanager.py::test_sync_state - AttributeEr... FAILED tests/test_dependency_contextmanager.py::test_async_raise_other - Attr... FAILED tests/test_dependency_contextmanager.py::test_sync_raise_other - Attri... FAILED tests/test_dependency_contextmanager.py::test_async_raise - AttributeE... FAILED tests/test_dependency_contextmanager.py::test_context_b - AttributeErr... FAILED tests/test_dependency_contextmanager.py::test_context_b_raise - Attrib... FAILED tests/test_dependency_contextmanager.py::test_background_tasks - Attri... FAILED tests/test_dependency_contextmanager.py::test_sync_raise - AttributeEr... FAILED tests/test_dependency_contextmanager.py::test_sync_async_state - Attri... FAILED tests/test_dependency_contextmanager.py::test_sync_sync_state - Attrib... FAILED tests/test_dependency_contextmanager.py::test_sync_async_raise_other FAILED tests/test_dependency_contextmanager.py::test_sync_sync_raise_other - ... FAILED tests/test_dependency_contextmanager.py::test_sync_async_raise - Attri... FAILED tests/test_dependency_contextmanager.py::test_sync_sync_raise - Attrib... FAILED tests/test_dependency_contextmanager.py::test_sync_context_b - Attribu... FAILED tests/test_dependency_contextmanager.py::test_sync_context_b_raise - A... FAILED tests/test_dependency_contextmanager.py::test_sync_background_tasks - ... FAILED tests/test_dependency_duplicates.py::test_openapi_schema - AttributeEr... FAILED tests/test_dependency_duplicates.py::test_no_duplicates_invalid - Attr... FAILED tests/test_dependency_duplicates.py::test_no_duplicates - AttributeErr... FAILED tests/test_dependency_duplicates.py::test_duplicates - AttributeError:... FAILED tests/test_dependency_duplicates.py::test_sub_duplicates - AttributeEr... FAILED tests/test_dependency_overrides.py::test_normal_app[/main-depends/-422-expected0] FAILED tests/test_dependency_overrides.py::test_normal_app[/main-depends/?q=foo-200-expected1] FAILED tests/test_dependency_overrides.py::test_normal_app[/main-depends/?q=foo&skip=100&limit=200-200-expected2] FAILED tests/test_dependency_overrides.py::test_normal_app[/decorator-depends/-422-expected3] FAILED tests/test_dependency_overrides.py::test_normal_app[/decorator-depends/?q=foo-200-expected4] FAILED tests/test_dependency_overrides.py::test_normal_app[/decorator-depends/?q=foo&skip=100&limit=200-200-expected5] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-depends/-422-expected6] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-depends/?q=foo-200-expected7] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-depends/?q=foo&skip=100&limit=200-200-expected8] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-decorator-depends/-422-expected9] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-decorator-depends/?q=foo-200-expected10] FAILED tests/test_dependency_overrides.py::test_normal_app[/router-decorator-depends/?q=foo&skip=100&limit=200-200-expected11] FAILED tests/test_dependency_overrides.py::test_override_simple[/main-depends/-200-expected0] FAILED tests/test_dependency_overrides.py::test_override_simple[/main-depends/?q=foo-200-expected1] FAILED tests/test_dependency_overrides.py::test_override_simple[/main-depends/?q=foo&skip=100&limit=200-200-expected2] FAILED tests/test_dependency_overrides.py::test_override_simple[/decorator-depends/-200-expected3] FAILED tests/test_dependency_overrides.py::test_override_simple[/router-depends/-200-expected4] FAILED tests/test_dependency_overrides.py::test_override_simple[/router-depends/?q=foo-200-expected5] FAILED tests/test_dependency_overrides.py::test_override_simple[/router-depends/?q=foo&skip=100&limit=200-200-expected6] FAILED tests/test_dependency_overrides.py::test_override_simple[/router-decorator-depends/-200-expected7] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/main-depends/-422-expected0] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/main-depends/?q=foo-422-expected1] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/main-depends/?k=bar-200-expected2] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/decorator-depends/-422-expected3] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/decorator-depends/?q=foo-422-expected4] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/decorator-depends/?k=bar-200-expected5] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-depends/-422-expected6] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-depends/?q=foo-422-expected7] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-depends/?k=bar-200-expected8] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-decorator-depends/-422-expected9] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-decorator-depends/?q=foo-422-expected10] FAILED tests/test_dependency_overrides.py::test_override_with_sub[/router-decorator-depends/?k=bar-200-expected11] FAILED tests/test_dependency_security_overrides.py::test_normal - AttributeEr... FAILED tests/test_dependency_security_overrides.py::test_override_data - Attr... FAILED tests/test_dependency_security_overrides.py::test_override_security - ... FAILED tests/test_deprecated_openapi_prefix.py::test_openapi - AttributeError... FAILED tests/test_deprecated_openapi_prefix.py::test_main - AttributeError: m... FAILED tests/test_duplicate_models_openapi.py::test_openapi_schema - Attribut... FAILED tests/test_duplicate_models_openapi.py::test_get_api_route - Attribute... FAILED tests/test_empty_router.py::test_use_empty - AttributeError: 'Blocking... FAILED tests/test_exception_handlers.py::test_override_http_exception - Attri... FAILED tests/test_exception_handlers.py::test_override_request_validation_exception FAILED tests/test_extra_routes.py::test_openapi_schema - AttributeError: modu... FAILED tests/test_extra_routes.py::test_get_api_route - AttributeError: modul... FAILED tests/test_extra_routes.py::test_get_api_route_not_decorated - Attribu... FAILED tests/test_extra_routes.py::test_delete - AttributeError: module 'anyi... FAILED tests/test_extra_routes.py::test_head - AttributeError: module 'anyio'... FAILED tests/test_extra_routes.py::test_options - AttributeError: module 'any... FAILED tests/test_extra_routes.py::test_patch - AttributeError: module 'anyio... FAILED tests/test_extra_routes.py::test_trace - AttributeError: module 'anyio... FAILED tests/test_filter_pydantic_sub_model.py::test_openapi_schema - Attribu... FAILED tests/test_filter_pydantic_sub_model.py::test_filter_sub_model - Attri... FAILED tests/test_filter_pydantic_sub_model.py::test_validator_is_cloned - At... FAILED tests/test_forms_from_non_typing_sequences.py::test_python_list_param_as_form FAILED tests/test_forms_from_non_typing_sequences.py::test_python_set_param_as_form FAILED tests/test_forms_from_non_typing_sequences.py::test_python_tuple_param_as_form FAILED tests/test_get_request_body.py::test_openapi_schema - AttributeError: ... FAILED tests/test_get_request_body.py::test_get_with_body - AttributeError: m... FAILED tests/test_http_connection_injection.py::test_value_extracting_by_http FAILED tests/test_http_connection_injection.py::test_value_extracting_by_ws FAILED tests/test_include_route.py::test_sub_router - AttributeError: module ... FAILED tests/test_include_router_defaults_overrides.py::test_openapi - Attrib... FAILED tests/test_include_router_defaults_overrides.py::test_level1_override FAILED tests/test_include_router_defaults_overrides.py::test_level1_default FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[True-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[True-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[True-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[True-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[False-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[False-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[False-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level3[False-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-True-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-True-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-True-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-True-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-False-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-False-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-False-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-True-False-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-True-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-True-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-True-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-True-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-False-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-False-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-False-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[True-False-False-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-True-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-True-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-True-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-True-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-False-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-False-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-False-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-True-False-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-True-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-True-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-True-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-True-False-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-False-True-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-False-True-False] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-False-False-True] FAILED tests/test_include_router_defaults_overrides.py::test_paths_level5[False-False-False-False-False] FAILED tests/test_infer_param_optionality.py::test_get_users - AttributeError... FAILED tests/test_infer_param_optionality.py::test_get_user - AttributeError:... FAILED tests/test_infer_param_optionality.py::test_get_items_1 - AttributeErr... FAILED tests/test_infer_param_optionality.py::test_get_items_2 - AttributeErr... FAILED tests/test_infer_param_optionality.py::test_get_item_1 - AttributeErro... FAILED tests/test_infer_param_optionality.py::test_get_item_2 - AttributeErro... FAILED tests/test_infer_param_optionality.py::test_get_users_items - Attribut... FAILED tests/test_infer_param_optionality.py::test_get_users_item - Attribute... FAILED tests/test_infer_param_optionality.py::test_schema_1 - AttributeError:... FAILED tests/test_infer_param_optionality.py::test_schema_2 - AttributeError:... FAILED tests/test_inherited_custom_class.py::test_dt - AttributeError: 'Block... FAILED tests/test_multi_body_errors.py::test_openapi_schema - AttributeError:... FAILED tests/test_multi_body_errors.py::test_put_correct_body - AttributeErro... FAILED tests/test_multi_body_errors.py::test_jsonable_encoder_requiring_error FAILED tests/test_multi_body_errors.py::test_put_incorrect_body_multiple - At... FAILED tests/test_multi_query_errors.py::test_openapi_schema - AttributeError... FAILED tests/test_multi_query_errors.py::test_multi_query - AttributeError: m... FAILED tests/test_multi_query_errors.py::test_multi_query_incorrect - Attribu... FAILED tests/test_no_swagger_ui_redirect.py::test_swagger_ui - AttributeError... FAILED tests/test_no_swagger_ui_redirect.py::test_swagger_ui_no_oauth2_redirect FAILED tests/test_no_swagger_ui_redirect.py::test_response - AttributeError: ... FAILED tests/test_openapi_servers.py::test_openapi_servers - AttributeError: ... FAILED tests/test_openapi_servers.py::test_app - AttributeError: module 'anyi... FAILED tests/test_param_class.py::test_default_param_query_none - AttributeEr... FAILED tests/test_param_class.py::test_default_param_query - AttributeError: ... FAILED tests/test_param_in_path_and_dependency.py::test_reused_param - Attrib... FAILED tests/test_param_in_path_and_dependency.py::test_read_users - Attribut... FAILED tests/test_path.py::test_text_get - AttributeError: module 'anyio' has... FAILED tests/test_path.py::test_nonexistent - AttributeError: module 'anyio' ... FAILED tests/test_path.py::test_get_path[/path/foobar-200-foobar] - Attribute... FAILED tests/test_path.py::test_get_path[/path/str/foobar-200-foobar] - Attri... FAILED tests/test_path.py::test_get_path[/path/str/42-200-42] - AttributeErro... FAILED tests/test_path.py::test_get_path[/path/str/True-200-True] - Attribute... FAILED tests/test_path.py::test_get_path[/path/int/foobar-422-expected_response4] FAILED tests/test_path.py::test_get_path[/path/int/True-422-expected_response5] FAILED tests/test_path.py::test_get_path[/path/int/42-200-42] - AttributeErro... FAILED tests/test_path.py::test_get_path[/path/int/42.5-422-expected_response7] FAILED tests/test_path.py::test_get_path[/path/float/foobar-422-expected_response8] FAILED tests/test_path.py::test_get_path[/path/float/True-422-expected_response9] FAILED tests/test_path.py::test_get_path[/path/float/42-200-42] - AttributeEr... FAILED tests/test_path.py::test_get_path[/path/float/42.5-200-42.5] - Attribu... FAILED tests/test_path.py::test_get_path[/path/bool/foobar-422-expected_response12] FAILED tests/test_path.py::test_get_path[/path/bool/True-200-True] - Attribut... FAILED tests/test_path.py::test_get_path[/path/bool/42-422-expected_response14] FAILED tests/test_path.py::test_get_path[/path/bool/42.5-422-expected_response15] FAILED tests/test_path.py::test_get_path[/path/bool/1-200-True] - AttributeEr... FAILED tests/test_path.py::test_get_path[/path/bool/0-200-False] - AttributeE... FAILED tests/test_path.py::test_get_path[/path/bool/true-200-True] - Attribut... FAILED tests/test_path.py::test_get_path[/path/bool/False-200-False] - Attrib... FAILED tests/test_path.py::test_get_path[/path/bool/false-200-False] - Attrib... FAILED tests/test_path.py::test_get_path[/path/param/foo-200-foo] - Attribute... FAILED tests/test_path.py::test_get_path[/path/param-required/foo-200-foo] - ... FAILED tests/test_path.py::test_get_path[/path/param-minlength/foo-200-foo] FAILED tests/test_path.py::test_get_path[/path/param-minlength/fo-422-expected_response24] FAILED tests/test_path.py::test_get_path[/path/param-maxlength/foo-200-foo] FAILED tests/test_path.py::test_get_path[/path/param-maxlength/foobar-422-expected_response26] FAILED tests/test_path.py::test_get_path[/path/param-min_maxlength/foo-200-foo] FAILED tests/test_path.py::test_get_path[/path/param-min_maxlength/foobar-422-expected_response28] FAILED tests/test_path.py::test_get_path[/path/param-min_maxlength/f-422-expected_response29] FAILED tests/test_path.py::test_get_path[/path/param-gt/42-200-42] - Attribut... FAILED tests/test_path.py::test_get_path[/path/param-gt/2-422-expected_response31] FAILED tests/test_path.py::test_get_path[/path/param-gt0/0.05-200-0.05] - Att... FAILED tests/test_path.py::test_get_path[/path/param-gt0/0-422-expected_response33] FAILED tests/test_path.py::test_get_path[/path/param-ge/42-200-42] - Attribut... FAILED tests/test_path.py::test_get_path[/path/param-ge/3-200-3] - AttributeE... FAILED tests/test_path.py::test_get_path[/path/param-ge/2-422-expected_response36] FAILED tests/test_path.py::test_get_path[/path/param-lt/42-422-expected_response37] FAILED tests/test_path.py::test_get_path[/path/param-lt/2-200-2] - AttributeE... FAILED tests/test_path.py::test_get_path[/path/param-lt0/-1-200--1] - Attribu... FAILED tests/test_path.py::test_get_path[/path/param-lt0/0-422-expected_response40] FAILED tests/test_path.py::test_get_path[/path/param-le/42-422-expected_response41] FAILED tests/test_path.py::test_get_path[/path/param-le/3-200-3] - AttributeE... FAILED tests/test_path.py::test_get_path[/path/param-le/2-200-2] - AttributeE... FAILED tests/test_path.py::test_get_path[/path/param-lt-gt/2-200-2] - Attribu... FAILED tests/test_path.py::test_get_path[/path/param-lt-gt/4-422-expected_response45] FAILED tests/test_path.py::test_get_path[/path/param-lt-gt/0-422-expected_response46] FAILED tests/test_path.py::test_get_path[/path/param-le-ge/2-200-2] - Attribu... FAILED tests/test_path.py::test_get_path[/path/param-le-ge/1-200-1] - Attribu... FAILED tests/test_path.py::test_get_path[/path/param-le-ge/3-200-3] - Attribu... FAILED tests/test_path.py::test_get_path[/path/param-le-ge/4-422-expected_response50] FAILED tests/test_path.py::test_get_path[/path/param-lt-int/2-200-2] - Attrib... FAILED tests/test_path.py::test_get_path[/path/param-lt-int/42-422-expected_response52] FAILED tests/test_path.py::test_get_path[/path/param-lt-int/2.7-422-expected_response53] FAILED tests/test_path.py::test_get_path[/path/param-gt-int/42-200-42] - Attr... FAILED tests/test_path.py::test_get_path[/path/param-gt-int/2-422-expected_response55] FAILED tests/test_path.py::test_get_path[/path/param-gt-int/2.7-422-expected_response56] FAILED tests/test_path.py::test_get_path[/path/param-le-int/42-422-expected_response57] FAILED tests/test_path.py::test_get_path[/path/param-le-int/3-200-3] - Attrib... FAILED tests/test_path.py::test_get_path[/path/param-le-int/2-200-2] - Attrib... FAILED tests/test_path.py::test_get_path[/path/param-le-int/2.7-422-expected_response60] FAILED tests/test_path.py::test_get_path[/path/param-ge-int/42-200-42] - Attr... FAILED tests/test_path.py::test_get_path[/path/param-ge-int/3-200-3] - Attrib... FAILED tests/test_path.py::test_get_path[/path/param-ge-int/2-422-expected_response63] FAILED tests/test_path.py::test_get_path[/path/param-ge-int/2.7-422-expected_response64] FAILED tests/test_path.py::test_get_path[/path/param-lt-gt-int/2-200-2] - Att... FAILED tests/test_path.py::test_get_path[/path/param-lt-gt-int/4-422-expected_response66] FAILED tests/test_path.py::test_get_path[/path/param-lt-gt-int/0-422-expected_response67] FAILED tests/test_path.py::test_get_path[/path/param-lt-gt-int/2.7-422-expected_response68] FAILED tests/test_path.py::test_get_path[/path/param-le-ge-int/2-200-2] - Att... FAILED tests/test_path.py::test_get_path[/path/param-le-ge-int/1-200-1] - Att... FAILED tests/test_path.py::test_get_path[/path/param-le-ge-int/3-200-3] - Att... FAILED tests/test_path.py::test_get_path[/path/param-le-ge-int/4-422-expected_response72] FAILED tests/test_path.py::test_get_path[/path/param-le-ge-int/2.7-422-expected_response73] FAILED tests/test_put_no_body.py::test_openapi_schema - AttributeError: modul... FAILED tests/test_put_no_body.py::test_put_no_body - AttributeError: module '... FAILED tests/test_put_no_body.py::test_put_no_body_with_body - AttributeError... FAILED tests/test_query.py::test_get_path[/query-422-expected_response0] - At... FAILED tests/test_query.py::test_get_path[/query?query=baz-200-foo bar baz] FAILED tests/test_query.py::test_get_path[/query?not_declared=baz-422-expected_response2] FAILED tests/test_query.py::test_get_path[/query/optional-200-foo bar] - Attr... FAILED tests/test_query.py::test_get_path[/query/optional?query=baz-200-foo bar baz] FAILED tests/test_query.py::test_get_path[/query/optional?not_declared=baz-200-foo bar] FAILED tests/test_query.py::test_get_path[/query/int-422-expected_response6] FAILED tests/test_query.py::test_get_path[/query/int?query=42-200-foo bar 42] FAILED tests/test_query.py::test_get_path[/query/int?query=42.5-422-expected_response8] FAILED tests/test_query.py::test_get_path[/query/int?query=baz-422-expected_response9] FAILED tests/test_query.py::test_get_path[/query/int?not_declared=baz-422-expected_response10] FAILED tests/test_query.py::test_get_path[/query/int/optional-200-foo bar] - ... FAILED tests/test_query.py::test_get_path[/query/int/optional?query=50-200-foo bar 50] FAILED tests/test_query.py::test_get_path[/query/int/optional?query=foo-422-expected_response13] FAILED tests/test_query.py::test_get_path[/query/int/default-200-foo bar 10] FAILED tests/test_query.py::test_get_path[/query/int/default?query=50-200-foo bar 50] FAILED tests/test_query.py::test_get_path[/query/int/default?query=foo-422-expected_response16] FAILED tests/test_query.py::test_get_path[/query/param-200-foo bar] - Attribu... FAILED tests/test_query.py::test_get_path[/query/param?query=50-200-foo bar 50] FAILED tests/test_query.py::test_get_path[/query/param-required-422-expected_response19] FAILED tests/test_query.py::test_get_path[/query/param-required?query=50-200-foo bar 50] FAILED tests/test_query.py::test_get_path[/query/param-required/int-422-expected_response21] FAILED tests/test_query.py::test_get_path[/query/param-required/int?query=50-200-foo bar 50] FAILED tests/test_query.py::test_get_path[/query/param-required/int?query=foo-422-expected_response23] FAILED tests/test_repeated_cookie_headers.py::test_cookie_is_set_once - Attri... FAILED tests/test_repeated_dependency_schema.py::test_schema - AttributeError... FAILED tests/test_repeated_dependency_schema.py::test_response - AttributeErr... FAILED tests/test_request_body_parameters_media_type.py::test_openapi_schema FAILED tests/test_response_change_status_code.py::test_dependency_set_status_code FAILED tests/test_response_class_no_mediatype.py::test_openapi_schema - Attri... FAILED tests/test_response_code_no_body.py::test_openapi_schema - AttributeEr... FAILED tests/test_response_model_sub_types.py::test_openapi_schema - Attribut... FAILED tests/test_response_model_sub_types.py::test_path_operations - Attribu... FAILED tests/test_router_events.py::test_router_events - AttributeError: 'Blo... FAILED tests/test_router_prefix_with_template.py::test_get - AttributeError: ... FAILED tests/test_security_api_key_cookie.py::test_openapi_schema - Attribute... FAILED tests/test_security_api_key_cookie.py::test_security_api_key - Attribu... FAILED tests/test_security_api_key_cookie.py::test_security_api_key_no_key - ... FAILED tests/test_security_api_key_cookie_optional.py::test_openapi_schema - ... FAILED tests/test_security_api_key_cookie_optional.py::test_security_api_key FAILED tests/test_security_api_key_cookie_optional.py::test_security_api_key_no_key FAILED tests/test_security_api_key_header.py::test_openapi_schema - Attribute... FAILED tests/test_security_api_key_header.py::test_security_api_key - Attribu... FAILED tests/test_security_api_key_header.py::test_security_api_key_no_key - ... FAILED tests/test_security_api_key_header_optional.py::test_openapi_schema - ... FAILED tests/test_security_api_key_header_optional.py::test_security_api_key FAILED tests/test_security_api_key_header_optional.py::test_security_api_key_no_key FAILED tests/test_security_api_key_query.py::test_openapi_schema - AttributeE... FAILED tests/test_security_api_key_query.py::test_security_api_key - Attribut... FAILED tests/test_security_api_key_query.py::test_security_api_key_no_key - A... FAILED tests/test_security_api_key_query_optional.py::test_openapi_schema - A... FAILED tests/test_security_api_key_query_optional.py::test_security_api_key FAILED tests/test_security_api_key_query_optional.py::test_security_api_key_no_key FAILED tests/test_security_http_base.py::test_openapi_schema - AttributeError... FAILED tests/test_security_http_base.py::test_security_http_base - AttributeE... FAILED tests/test_security_http_base.py::test_security_http_base_no_credentials FAILED tests/test_security_http_base_optional.py::test_openapi_schema - Attri... FAILED tests/test_security_http_base_optional.py::test_security_http_base - A... FAILED tests/test_security_http_base_optional.py::test_security_http_base_no_credentials FAILED tests/test_security_http_basic_optional.py::test_openapi_schema - Attr... FAILED tests/test_security_http_basic_optional.py::test_security_http_basic FAILED tests/test_security_http_basic_optional.py::test_security_http_basic_no_credentials FAILED tests/test_security_http_basic_optional.py::test_security_http_basic_invalid_credentials FAILED tests/test_security_http_basic_optional.py::test_security_http_basic_non_basic_credentials FAILED tests/test_security_http_basic_realm.py::test_openapi_schema - Attribu... FAILED tests/test_security_http_basic_realm.py::test_security_http_basic - At... FAILED tests/test_security_http_basic_realm.py::test_security_http_basic_no_credentials FAILED tests/test_security_http_basic_realm.py::test_security_http_basic_invalid_credentials FAILED tests/test_security_http_basic_realm.py::test_security_http_basic_non_basic_credentials FAILED tests/test_security_http_bearer.py::test_openapi_schema - AttributeErr... FAILED tests/test_security_http_bearer.py::test_security_http_bearer - Attrib... FAILED tests/test_security_http_bearer.py::test_security_http_bearer_no_credentials FAILED tests/test_security_http_bearer.py::test_security_http_bearer_incorrect_scheme_credentials FAILED tests/test_security_http_bearer_optional.py::test_openapi_schema - Att... FAILED tests/test_security_http_bearer_optional.py::test_security_http_bearer FAILED tests/test_security_http_bearer_optional.py::test_security_http_bearer_no_credentials FAILED tests/test_security_http_bearer_optional.py::test_security_http_bearer_incorrect_scheme_credentials FAILED tests/test_security_http_digest.py::test_openapi_schema - AttributeErr... FAILED tests/test_security_http_digest.py::test_security_http_digest - Attrib... FAILED tests/test_security_http_digest.py::test_security_http_digest_no_credentials FAILED tests/test_security_http_digest.py::test_security_http_digest_incorrect_scheme_credentials FAILED tests/test_security_http_digest_optional.py::test_openapi_schema - Att... FAILED tests/test_security_http_digest_optional.py::test_security_http_digest FAILED tests/test_security_http_digest_optional.py::test_security_http_digest_no_credentials FAILED tests/test_security_http_digest_optional.py::test_security_http_digest_incorrect_scheme_credentials FAILED tests/test_security_oauth2.py::test_openapi_schema - AttributeError: m... FAILED tests/test_security_oauth2.py::test_security_oauth2 - AttributeError: ... FAILED tests/test_security_oauth2.py::test_security_oauth2_password_other_header FAILED tests/test_security_oauth2.py::test_security_oauth2_password_bearer_no_header FAILED tests/test_security_oauth2.py::test_strict_login[None-422-expected_response0] FAILED tests/test_security_oauth2.py::test_strict_login[data1-422-expected_response1] FAILED tests/test_security_oauth2.py::test_strict_login[data2-422-expected_response2] FAILED tests/test_security_oauth2.py::test_strict_login[data3-200-expected_response3] FAILED tests/test_security_oauth2_authorization_code_bearer.py::test_openapi_schema FAILED tests/test_security_oauth2_authorization_code_bearer.py::test_no_token FAILED tests/test_security_oauth2_authorization_code_bearer.py::test_incorrect_token FAILED tests/test_security_oauth2_authorization_code_bearer.py::test_token - ... FAILED tests/test_security_oauth2_optional.py::test_openapi_schema - Attribut... FAILED tests/test_security_oauth2_optional.py::test_security_oauth2 - Attribu... FAILED tests/test_security_oauth2_optional.py::test_security_oauth2_password_other_header FAILED tests/test_security_oauth2_optional.py::test_security_oauth2_password_bearer_no_header FAILED tests/test_security_oauth2_optional.py::test_strict_login[None-422-expected_response0] FAILED tests/test_security_oauth2_optional.py::test_strict_login[data1-422-expected_response1] FAILED tests/test_security_oauth2_optional.py::test_strict_login[data2-422-expected_response2] FAILED tests/test_security_oauth2_optional.py::test_strict_login[data3-200-expected_response3] FAILED tests/test_security_oauth2_password_bearer_optional.py::test_openapi_schema FAILED tests/test_security_oauth2_password_bearer_optional.py::test_no_token FAILED tests/test_security_oauth2_password_bearer_optional.py::test_token - A... FAILED tests/test_security_oauth2_password_bearer_optional.py::test_incorrect_token FAILED tests/test_security_openid_connect.py::test_openapi_schema - Attribute... FAILED tests/test_security_openid_connect.py::test_security_oauth2 - Attribut... FAILED tests/test_security_openid_connect.py::test_security_oauth2_password_other_header FAILED tests/test_security_openid_connect.py::test_security_oauth2_password_bearer_no_header FAILED tests/test_security_openid_connect_optional.py::test_openapi_schema - ... FAILED tests/test_security_openid_connect_optional.py::test_security_oauth2 FAILED tests/test_security_openid_connect_optional.py::test_security_oauth2_password_other_header FAILED tests/test_security_openid_connect_optional.py::test_security_oauth2_password_bearer_no_header FAILED tests/test_serialize_response.py::test_valid - AttributeError: module ... FAILED tests/test_serialize_response.py::test_coerce - AttributeError: module... FAILED tests/test_serialize_response.py::test_validlist - AttributeError: mod... FAILED tests/test_serialize_response_dataclass.py::test_valid - AttributeErro... FAILED tests/test_serialize_response_dataclass.py::test_coerce - AttributeErr... FAILED tests/test_serialize_response_dataclass.py::test_validlist - Attribute... FAILED tests/test_serialize_response_model.py::test_valid - AttributeError: m... FAILED tests/test_serialize_response_model.py::test_coerce - AttributeError: ... FAILED tests/test_serialize_response_model.py::test_validlist - AttributeErro... FAILED tests/test_serialize_response_model.py::test_validdict - AttributeErro... FAILED tests/test_serialize_response_model.py::test_valid_exclude_unset - Att... FAILED tests/test_serialize_response_model.py::test_coerce_exclude_unset - At... FAILED tests/test_serialize_response_model.py::test_validlist_exclude_unset FAILED tests/test_serialize_response_model.py::test_validdict_exclude_unset FAILED tests/test_skip_defaults.py::test_return_defaults - AttributeError: mo... FAILED tests/test_skip_defaults.py::test_return_exclude_unset - AttributeErro... FAILED tests/test_skip_defaults.py::test_return_exclude_defaults - AttributeE... FAILED tests/test_skip_defaults.py::test_return_exclude_none - AttributeError... FAILED tests/test_skip_defaults.py::test_return_exclude_unset_none - Attribut... FAILED tests/test_starlette_exception.py::test_openapi_schema - AttributeErro... FAILED tests/test_starlette_exception.py::test_get_item - AttributeError: mod... FAILED tests/test_starlette_exception.py::test_get_item_not_found - Attribute... FAILED tests/test_starlette_exception.py::test_get_starlette_item - Attribute... FAILED tests/test_starlette_exception.py::test_get_starlette_item_not_found FAILED tests/test_starlette_urlconvertors.py::test_route_converters_int - Att... FAILED tests/test_starlette_urlconvertors.py::test_route_converters_float - A... FAILED tests/test_starlette_urlconvertors.py::test_route_converters_path - At... FAILED tests/test_sub_callbacks.py::test_openapi - AttributeError: 'BlockingP... FAILED tests/test_sub_callbacks.py::test_get - AttributeError: module 'anyio'... FAILED tests/test_swagger_ui_init_oauth.py::test_swagger_ui - AttributeError:... FAILED tests/test_swagger_ui_init_oauth.py::test_response - AttributeError: m... FAILED tests/test_union_body.py::test_item_openapi_schema - AttributeError: m... FAILED tests/test_union_body.py::test_post_other_item - AttributeError: modul... FAILED tests/test_union_body.py::test_post_item - AttributeError: module 'any... FAILED tests/test_union_inherited_body.py::test_inherited_item_openapi_schema FAILED tests/test_union_inherited_body.py::test_post_extended_item - Attribut... FAILED tests/test_union_inherited_body.py::test_post_item - AttributeError: m... FAILED tests/test_validate_response.py::test_invalid - AttributeError: module... FAILED tests/test_validate_response.py::test_double_invalid - AttributeError:... FAILED tests/test_validate_response.py::test_invalid_list - AttributeError: m... FAILED tests/test_validate_response_dataclass.py::test_invalid - AttributeErr... FAILED tests/test_validate_response_dataclass.py::test_double_invalid - Attri... FAILED tests/test_validate_response_dataclass.py::test_invalid_list - Attribu... FAILED tests/test_validate_response_recursive.py::test_recursive - AttributeE... FAILED tests/test_ws_router.py::test_app - AttributeError: 'BlockingPortal' o... FAILED tests/test_ws_router.py::test_router - AttributeError: 'BlockingPortal... FAILED tests/test_ws_router.py::test_prefix_router - AttributeError: 'Blockin... FAILED tests/test_ws_router.py::test_router2 - AttributeError: 'BlockingPorta... FAILED tests/test_ws_router.py::test_router_ws_depends - AttributeError: 'Blo... FAILED tests/test_ws_router.py::test_router_ws_depends_with_override - Attrib... FAILED tests/test_modules_same_name_body/test_main.py::test_openapi_schema - ... FAILED tests/test_modules_same_name_body/test_main.py::test_post_a - Attribut... FAILED tests/test_modules_same_name_body/test_main.py::test_post_a_invalid - ... FAILED tests/test_modules_same_name_body/test_main.py::test_post_b - Attribut... FAILED tests/test_modules_same_name_body/test_main.py::test_post_b_invalid - ... FAILED tests/test_tutorial/test_additional_responses/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_additional_responses/test_tutorial001.py::test_path_operation FAILED tests/test_tutorial/test_additional_responses/test_tutorial001.py::test_path_operation_not_found FAILED tests/test_tutorial/test_additional_responses/test_tutorial002.py::test_openapi_schema FAILED tests/test_tutorial/test_additional_responses/test_tutorial002.py::test_path_operation FAILED tests/test_tutorial/test_additional_responses/test_tutorial002.py::test_path_operation_img FAILED tests/test_tutorial/test_additional_responses/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_additional_responses/test_tutorial003.py::test_path_operation FAILED tests/test_tutorial/test_additional_responses/test_tutorial003.py::test_path_operation_not_found FAILED tests/test_tutorial/test_additional_responses/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_additional_responses/test_tutorial004.py::test_path_operation FAILED tests/test_tutorial/test_additional_responses/test_tutorial004.py::test_path_operation_img FAILED tests/test_tutorial/test_additional_status_codes/test_tutorial001.py::test_update FAILED tests/test_tutorial/test_additional_status_codes/test_tutorial001.py::test_create FAILED tests/test_tutorial/test_advanced_middleware/test_tutorial001.py::test_middleware FAILED tests/test_tutorial/test_advanced_middleware/test_tutorial002.py::test_middleware FAILED tests/test_tutorial/test_advanced_middleware/test_tutorial003.py::test_middleware FAILED tests/test_tutorial/test_async_sql_databases/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_async_sql_databases/test_tutorial001.py::test_create_read FAILED tests/test_tutorial/test_async_tests/test_main.py::test_root - Attribu... FAILED tests/test_tutorial/test_async_tests/test_main.py::test_async_testing FAILED tests/test_tutorial/test_background_tasks/test_tutorial001.py::test - ... FAILED tests/test_tutorial/test_background_tasks/test_tutorial002.py::test - ... FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py::test_openapi FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial001.py::test_main FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py::test_openapi FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial002.py::test_main FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py::test_openapi FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial003.py::test_main FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial004.py::test_openapi FAILED tests/test_tutorial/test_behind_a_proxy/test_tutorial004.py::test_main FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users?token=jessica-200-expected_response0-headers0] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users-422-expected_response1-headers1] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users/foo?token=jessica-200-expected_response2-headers2] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users/foo-422-expected_response3-headers3] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users/me?token=jessica-200-expected_response4-headers4] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/users/me-422-expected_response5-headers5] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items?token=jessica-200-expected_response6-headers6] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items-422-expected_response7-headers7] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items/plumbus?token=jessica-200-expected_response8-headers8] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items/plumbus-422-expected_response9-headers9] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items?token=jessica-400-expected_response10-headers10] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items/bar?token=jessica-400-expected_response11-headers11] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items?token=jessica-422-expected_response12-headers12] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/items/plumbus?token=jessica-422-expected_response13-headers13] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/?token=jessica-200-expected_response14-headers14] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/-422-expected_response15-headers15] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_get_path[/openapi.json-200-expected_response16-headers16] FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_put_no_header FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_put_invalid_header FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_put - ... FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_put_forbidden FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_admin FAILED tests/test_tutorial/test_bigger_applications/test_main.py::test_admin_invalid_header FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body0-200-expected_response0] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body1-200-expected_response1] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body2-200-expected_response2] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body3-200-expected_response3] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body4-422-expected_response4] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body5-422-expected_response5] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-body6-422-expected_response6] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_body[/items/-None-422-expected_response7] FAILED tests/test_tutorial/test_body/test_tutorial001.py::test_post_broken_body FAILED tests/test_tutorial/test_body_fields/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_body_fields/test_tutorial001.py::test[/items/5-body0-200-expected_response0] FAILED tests/test_tutorial/test_body_fields/test_tutorial001.py::test[/items/6-body1-200-expected_response1] FAILED tests/test_tutorial/test_body_fields/test_tutorial001.py::test[/items/5-body2-422-expected_response2] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial001.py::test_post_body[/items/5?q=bar-body0-200-expected_response0] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial001.py::test_post_body[/items/5?q=bar-None-200-expected_response1] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial001.py::test_post_body[/items/5-None-200-expected_response2] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial001.py::test_post_body[/items/foo-None-422-expected_response3] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial003.py::test_post_body[/items/5-body0-200-expected_response0] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial003.py::test_post_body[/items/5-None-422-expected_response1] FAILED tests/test_tutorial/test_body_multiple_params/test_tutorial003.py::test_post_body[/items/5-body2-422-expected_response2] FAILED tests/test_tutorial/test_body_nested_models/test_tutorial009.py::test_openapi_schema FAILED tests/test_tutorial/test_body_nested_models/test_tutorial009.py::test_post_body FAILED tests/test_tutorial/test_body_nested_models/test_tutorial009.py::test_post_invalid_body FAILED tests/test_tutorial/test_body_updates/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_body_updates/test_tutorial001.py::test_get - ... FAILED tests/test_tutorial/test_body_updates/test_tutorial001.py::test_put - ... FAILED tests/test_tutorial/test_conditional_openapi/test_tutorial001.py::test_default_openapi FAILED tests/test_tutorial/test_conditional_openapi/test_tutorial001.py::test_disable_openapi FAILED tests/test_tutorial/test_cookie_params/test_tutorial001.py::test[/openapi.json-None-200-expected_response0] FAILED tests/test_tutorial/test_cookie_params/test_tutorial001.py::test[/items-None-200-expected_response1] FAILED tests/test_tutorial/test_cookie_params/test_tutorial001.py::test[/items-cookies2-200-expected_response2] FAILED tests/test_tutorial/test_cookie_params/test_tutorial001.py::test[/items-cookies3-200-expected_response3] FAILED tests/test_tutorial/test_cookie_params/test_tutorial001.py::test[/items-cookies4-200-expected_response4] FAILED tests/test_tutorial/test_cors/test_tutorial001.py::test_cors - Attribu... FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py::test_gzip_request[True] FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py::test_gzip_request[False] FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py::test_request_class FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py::test_endpoint_works FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial002.py::test_exception_handler_body_access FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py::test_get FAILED tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py::test_get_timed FAILED tests/test_tutorial/test_custom_response/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_custom_response/test_tutorial001b.py::test_openapi_schema FAILED tests/test_tutorial/test_custom_response/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_custom_response/test_tutorial005.py::test_openapi_schema FAILED tests/test_tutorial/test_custom_response/test_tutorial005.py::test_get FAILED tests/test_tutorial/test_custom_response/test_tutorial006.py::test_get FAILED tests/test_tutorial/test_custom_response/test_tutorial007.py::test_get FAILED tests/test_tutorial/test_custom_response/test_tutorial008.py::test_get FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/items-200-expected_response0] FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/items?q=foo-200-expected_response1] FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/items?q=foo&skip=5-200-expected_response2] FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/items?q=foo&skip=5&limit=30-200-expected_response3] FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/users-200-expected_response4] FAILED tests/test_tutorial/test_dependencies/test_tutorial001.py::test_get[/openapi.json-200-expected_response5] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items-200-expected_response0] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items?q=foo-200-expected_response1] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items?q=foo&skip=1-200-expected_response2] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items?q=bar&limit=2-200-expected_response3] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items?q=bar&skip=1&limit=1-200-expected_response4] FAILED tests/test_tutorial/test_dependencies/test_tutorial004.py::test_get[/items?limit=1&q=bar&skip=1-200-expected_response5] FAILED tests/test_tutorial/test_dependencies/test_tutorial006.py::test_openapi_schema FAILED tests/test_tutorial/test_dependencies/test_tutorial006.py::test_get_no_headers FAILED tests/test_tutorial/test_dependencies/test_tutorial006.py::test_get_invalid_one_header FAILED tests/test_tutorial/test_dependencies/test_tutorial006.py::test_get_invalid_second_header FAILED tests/test_tutorial/test_dependencies/test_tutorial006.py::test_get_valid_headers FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_openapi_schema FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_no_headers_items FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_no_headers_users FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_invalid_one_header_items FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_invalid_one_users FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_invalid_second_header_items FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_invalid_second_header_users FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_valid_headers_items FAILED tests/test_tutorial/test_dependencies/test_tutorial012.py::test_get_valid_headers_users FAILED tests/test_tutorial/test_events/test_tutorial001.py::test_events - Att... FAILED tests/test_tutorial/test_events/test_tutorial002.py::test_events - Att... FAILED tests/test_tutorial/test_extending_openapi/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_extending_openapi/test_tutorial001.py::test FAILED tests/test_tutorial/test_extra_data_types/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_extra_data_types/test_tutorial001.py::test_extra_types FAILED tests/test_tutorial/test_extra_models/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_extra_models/test_tutorial003.py::test_get_car FAILED tests/test_tutorial/test_extra_models/test_tutorial003.py::test_get_plane FAILED tests/test_tutorial/test_extra_models/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_extra_models/test_tutorial004.py::test_get_items FAILED tests/test_tutorial/test_extra_models/test_tutorial005.py::test_openapi_schema FAILED tests/test_tutorial/test_extra_models/test_tutorial005.py::test_get_items FAILED tests/test_tutorial/test_first_steps/test_tutorial001.py::test_get_path[/-200-expected_response0] FAILED tests/test_tutorial/test_first_steps/test_tutorial001.py::test_get_path[/nonexistent-404-expected_response1] FAILED tests/test_tutorial/test_first_steps/test_tutorial001.py::test_get_path[/openapi.json-200-expected_response2] FAILED tests/test_tutorial/test_handling_errors/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial001.py::test_get_item FAILED tests/test_tutorial/test_handling_errors/test_tutorial001.py::test_get_item_not_found FAILED tests/test_tutorial/test_handling_errors/test_tutorial002.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial002.py::test_get_item_header FAILED tests/test_tutorial/test_handling_errors/test_tutorial002.py::test_get_item_not_found_header FAILED tests/test_tutorial/test_handling_errors/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial003.py::test_get FAILED tests/test_tutorial/test_handling_errors/test_tutorial003.py::test_get_exception FAILED tests/test_tutorial/test_handling_errors/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial004.py::test_get_validation_error FAILED tests/test_tutorial/test_handling_errors/test_tutorial004.py::test_get_http_error FAILED tests/test_tutorial/test_handling_errors/test_tutorial004.py::test_get FAILED tests/test_tutorial/test_handling_errors/test_tutorial005.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial005.py::test_post_validation_error FAILED tests/test_tutorial/test_handling_errors/test_tutorial005.py::test_post FAILED tests/test_tutorial/test_handling_errors/test_tutorial006.py::test_openapi_schema FAILED tests/test_tutorial/test_handling_errors/test_tutorial006.py::test_get_validation_error FAILED tests/test_tutorial/test_handling_errors/test_tutorial006.py::test_get_http_error FAILED tests/test_tutorial/test_handling_errors/test_tutorial006.py::test_get FAILED tests/test_tutorial/test_header_params/test_tutorial001.py::test[/openapi.json-None-200-expected_response0] FAILED tests/test_tutorial/test_header_params/test_tutorial001.py::test[/items-None-200-expected_response1] FAILED tests/test_tutorial/test_header_params/test_tutorial001.py::test[/items-headers2-200-expected_response2] FAILED tests/test_tutorial/test_header_params/test_tutorial001.py::test[/items-headers3-200-expected_response3] FAILED tests/test_tutorial/test_metadata/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_metadata/test_tutorial001.py::test_items - At... FAILED tests/test_tutorial/test_metadata/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_metadata/test_tutorial004.py::test_path_operations FAILED tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py::test_openapi FAILED tests/test_tutorial/test_openapi_callbacks/test_tutorial001.py::test_get FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial001.py::test_get FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial002.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial002.py::test_get FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial003.py::test_get FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py::test_query_params_str_validations FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial005.py::test_query_params_str_validations FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py::test_openapi_schema FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py::test_query_params_str_validations[/items/-200-expected_response0] FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py::test_query_params_str_validations[/users/-200-expected_response1] FAILED tests/test_tutorial/test_path_operation_configurations/test_tutorial006.py::test_query_params_str_validations[/elements/-200-expected_response2] FAILED tests/test_tutorial/test_path_params/test_tutorial004.py::test_openapi FAILED tests/test_tutorial/test_path_params/test_tutorial004.py::test_file_path FAILED tests/test_tutorial/test_path_params/test_tutorial004.py::test_root_file_path FAILED tests/test_tutorial/test_path_params/test_tutorial005.py::test_openapi FAILED tests/test_tutorial/test_path_params/test_tutorial005.py::test_get_enums[/models/alexnet-200-expected0] FAILED tests/test_tutorial/test_path_params/test_tutorial005.py::test_get_enums[/models/lenet-200-expected1] FAILED tests/test_tutorial/test_path_params/test_tutorial005.py::test_get_enums[/models/resnet-200-expected2] FAILED tests/test_tutorial/test_path_params/test_tutorial005.py::test_get_enums[/models/foo-422-expected3] FAILED tests/test_tutorial/test_query_params/test_tutorial005.py::test[/openapi.json-200-expected_response0] FAILED tests/test_tutorial/test_query_params/test_tutorial005.py::test[/items/foo?needy=very-200-expected_response1] FAILED tests/test_tutorial/test_query_params/test_tutorial005.py::test[/items/foo-422-expected_response2] FAILED tests/test_tutorial/test_query_params/test_tutorial005.py::test[/items/foo-422-expected_response3] FAILED tests/test_tutorial/test_query_params/test_tutorial006.py::test[/openapi.json-200-expected_response0] FAILED tests/test_tutorial/test_query_params/test_tutorial006.py::test[/items/foo?needy=very-200-expected_response1] FAILED tests/test_tutorial/test_query_params/test_tutorial006.py::test[/items/foo?skip=a&limit=b-422-expected_response2] FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py::test_query_params_str_validations[None-None-200-expected_response0] FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py::test_query_params_str_validations[item-query-fixedquery-200-expected_response1] FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py::test_query_params_str_validations[q-fixedquery-200-expected_response2] FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py::test_query_params_str_validations[item-query-nonregexquery-422-expected_response3] FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py::test_openapi_schema FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py::test_multi_query_values FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial011.py::test_query_no_values FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py::test_openapi_schema FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py::test_default_query_values FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py::test_multi_query_values FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py::test_openapi_schema FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py::test_multi_query_values FAILED tests/test_tutorial/test_query_params_str_validations/test_tutorial013.py::test_query_no_values FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_post_form_no_body FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_post_body_json FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_post_file FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_post_large_file FAILED tests/test_tutorial/test_request_files/test_tutorial001.py::test_post_upload_file FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_openapi_schema FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_post_form_no_body FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_post_body_json FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_post_files FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_post_upload_file FAILED tests/test_tutorial/test_request_files/test_tutorial002.py::test_get_root FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_post_body_form[/login/-body0-200-expected_response0] FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_post_body_form[/login/-body1-422-expected_response1] FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_post_body_form[/login/-body2-422-expected_response2] FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_post_body_form[/login/-None-422-expected_response3] FAILED tests/test_tutorial/test_request_forms/test_tutorial001.py::test_post_body_json FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_post_form_no_body FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_post_form_no_file FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_post_body_json FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_post_file_no_token FAILED tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py::test_post_files_and_token FAILED tests/test_tutorial/test_response_change_status_code/test_tutorial001.py::test_path_operation FAILED tests/test_tutorial/test_response_cookies/test_tutorial001.py::test_path_operation FAILED tests/test_tutorial/test_response_cookies/test_tutorial002.py::test_path_operation FAILED tests/test_tutorial/test_response_headers/test_tutorial001.py::test_path_operation FAILED tests/test_tutorial/test_response_headers/test_tutorial002.py::test_path_operation FAILED tests/test_tutorial/test_response_model/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_response_model/test_tutorial003.py::test_post_user FAILED tests/test_tutorial/test_response_model/test_tutorial004.py::test_openapi_schema FAILED tests/test_tutorial/test_response_model/test_tutorial004.py::test_get[/items/foo-data0] FAILED tests/test_tutorial/test_response_model/test_tutorial004.py::test_get[/items/bar-data1] FAILED tests/test_tutorial/test_response_model/test_tutorial004.py::test_get[/items/baz-data2] FAILED tests/test_tutorial/test_response_model/test_tutorial005.py::test_openapi_schema FAILED tests/test_tutorial/test_response_model/test_tutorial005.py::test_read_item_name FAILED tests/test_tutorial/test_response_model/test_tutorial005.py::test_read_item_public_data FAILED tests/test_tutorial/test_response_model/test_tutorial006.py::test_openapi_schema FAILED tests/test_tutorial/test_response_model/test_tutorial006.py::test_read_item_name FAILED tests/test_tutorial/test_response_model/test_tutorial006.py::test_read_item_public_data FAILED tests/test_tutorial/test_security/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_security/test_tutorial001.py::test_no_token FAILED tests/test_tutorial/test_security/test_tutorial001.py::test_token - At... FAILED tests/test_tutorial/test_security/test_tutorial001.py::test_incorrect_token FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_openapi_schema FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_login - At... FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_login_incorrect_password FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_login_incorrect_username FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_no_token FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_token - At... FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_incorrect_token FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_incorrect_token_type FAILED tests/test_tutorial/test_security/test_tutorial003.py::test_inactive_user FAILED tests/test_tutorial/test_security/test_tutorial006.py::test_openapi_schema FAILED tests/test_tutorial/test_security/test_tutorial006.py::test_security_http_basic FAILED tests/test_tutorial/test_security/test_tutorial006.py::test_security_http_basic_no_credentials FAILED tests/test_tutorial/test_security/test_tutorial006.py::test_security_http_basic_invalid_credentials FAILED tests/test_tutorial/test_security/test_tutorial006.py::test_security_http_basic_non_basic_credentials FAILED tests/test_tutorial/test_settings/test_app02.py::test_setting_override FAILED tests/test_tutorial/test_sql_databases/test_testing_databases.py::test_testing_dbs FAILED tests/test_tutorial/test_sub_applications/test_tutorial001.py::test_openapi_schema_main FAILED tests/test_tutorial/test_sub_applications/test_tutorial001.py::test_main FAILED tests/test_tutorial/test_sub_applications/test_tutorial001.py::test_openapi_schema_sub FAILED tests/test_tutorial/test_sub_applications/test_tutorial001.py::test_sub FAILED tests/test_tutorial/test_templates/test_tutorial001.py::test_main - At... FAILED tests/test_tutorial/test_testing/test_main.py::test_read_main - Attrib... FAILED tests/test_tutorial/test_testing/test_main.py::test_openapi_schema - A... FAILED tests/test_tutorial/test_testing/test_main.py::test_main - AttributeEr... FAILED tests/test_tutorial/test_testing/test_tutorial001.py::test_read_main FAILED tests/test_tutorial/test_testing/test_tutorial001.py::test_openapi_schema FAILED tests/test_tutorial/test_testing/test_tutorial001.py::test_main - Attr... FAILED tests/test_tutorial/test_testing/test_tutorial002.py::test_read_main FAILED tests/test_tutorial/test_testing/test_tutorial002.py::test_websocket FAILED tests/test_tutorial/test_testing/test_tutorial002.py::test_main - Attr... FAILED tests/test_tutorial/test_testing/test_tutorial002.py::test_ws - Attrib... FAILED tests/test_tutorial/test_testing/test_tutorial003.py::test_read_items FAILED tests/test_tutorial/test_testing/test_tutorial003.py::test_main - Attr... FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items_with_q FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items_with_params FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items_run FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items_with_q_run FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_items_with_params_run FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_users FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_users_with_q FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_override_in_users_with_params FAILED tests/test_tutorial/test_testing_dependencies/test_tutorial001.py::test_normal_app FAILED tests/test_tutorial/test_websockets/test_tutorial001.py::test_main - A... FAILED tests/test_tutorial/test_websockets/test_tutorial001.py::test_websocket FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_main - A... FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_websocket_with_cookie FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_websocket_with_header FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_websocket_with_header_and_query FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_websocket_no_credentials FAILED tests/test_tutorial/test_websockets/test_tutorial002.py::test_websocket_invalid_data FAILED tests/test_tutorial/test_websockets/test_tutorial003.py::test_websocket_handle_disconnection FAILED tests/test_tutorial/test_wsgi/test_tutorial001.py::test_flask - Attrib... FAILED tests/test_tutorial/test_wsgi/test_tutorial001.py::test_app - Attribut... ERROR tests/test_tutorial/test_extending_openapi/test_tutorial002.py::test_swagger_ui_html ERROR tests/test_tutorial/test_extending_openapi/test_tutorial002.py::test_swagger_ui_oauth2_redirect_html ERROR tests/test_tutorial/test_extending_openapi/test_tutorial002.py::test_redoc_html ERROR tests/test_tutorial/test_extending_openapi/test_tutorial002.py::test_api ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_openapi_schema ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_create_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_get_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_inexistent_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_get_users ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_create_item ERROR tests/test_tutorial/test_sql_databases/test_sql_databases.py::test_read_items ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_openapi_schema ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_create_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_get_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_inexistent_user ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_get_users ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_create_item ERROR tests/test_tutorial/test_sql_databases/test_sql_databases_middleware.py::test_read_items ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_openapi_schema ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_create_user ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_get_user ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_inexistent_user ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_get_users ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_get_slowusers ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_create_item ERROR tests/test_tutorial/test_sql_databases_peewee/test_sql_databases_peewee.py::test_read_items =========== 782 failed, 84 passed, 3 deselected, 26 errors in 37.76s =========== E: pybuild pybuild:367: test: plugin custom failed with: exit code=1: PYTHONPATH=/<>/build/lib/ python3.9 -m pytest tests/ --ignore=tests/test_default_response_class.py --ignore=tests/test_tutorial/test_security/test_tutorial005.py --ignore=tests/test_response_by_alias.py -k ' not test_get_custom_response' rm -fr -- /tmp/dh-xdg-rundir-Gzfh_4A3 dh_auto_test: error: pybuild --test --test-pytest -i python{version} -p "3.10 3.9" returned exit code 13 make[1]: *** [debian/rules:23: override_dh_auto_test] Error 25 make[1]: Leaving directory '/<>' make: *** [debian/rules:7: build] Error 2 dpkg-buildpackage.pl: error: debian/rules build subprocess returned exit status 2 === USAGE-SUMMARY BEGIN === SUMMARY: host: lcy02-amd64-032; CPUs: 4/4; CPU avg: 27%; CPU max: 78%; base memory: 0.2 GB; peak memory: 0.3 GB; total memory: 7.8 GB SUMMARY: swap peak/total: 0.0/0.0 GB; disk start/end/total: 2.7/2.7/77.4 GB; disk delta: 0.0 GB === USAGE-SUMMARY END === -------------------------------------------------------------------------------- Build finished at 2022-01-11T01:20:32Z Finished -------- +------------------------------------------------------------------------------+ | Cleanup | +------------------------------------------------------------------------------+ Purging /<> Not removing build depends: as requested E: Build failure (dpkg-buildpackage died) +------------------------------------------------------------------------------+ | Summary | +------------------------------------------------------------------------------+ Build Architecture: amd64 Build Type: binary Build-Space: n/a Build-Time: 79 Distribution: jammy Fail-Stage: build Host Architecture: amd64 Install-Time: 19 Job: fastapi_0.63.0-2.dsc Machine Architecture: amd64 Package: fastapi Package-Time: 100 Source-Version: 0.63.0-2 Space: n/a Status: attempted Version: 0.63.0-2 -------------------------------------------------------------------------------- Finished at 2022-01-11T01:20:32Z Build needed 00:01:40, no disk space E: Build failure (dpkg-buildpackage died) Adding user buildd to group lxd RUN: /usr/share/launchpad-buildd/bin/in-target scan-for-processes --backend=chroot --series=jammy --arch=amd64 PACKAGEBUILD-22760933 Scanning for processes to kill in build PACKAGEBUILD-22760933