summaryrefslogtreecommitdiff
path: root/python-sanic-testing.spec
diff options
context:
space:
mode:
Diffstat (limited to 'python-sanic-testing.spec')
-rw-r--r--python-sanic-testing.spec295
1 files changed, 295 insertions, 0 deletions
diff --git a/python-sanic-testing.spec b/python-sanic-testing.spec
new file mode 100644
index 0000000..3c7390f
--- /dev/null
+++ b/python-sanic-testing.spec
@@ -0,0 +1,295 @@
+%global _empty_manifest_terminate_build 0
+Name: python-sanic-testing
+Version: 23.3.0
+Release: 1
+Summary: Core testing clients for Sanic
+License: MIT
+URL: https://github.com/sanic-org/sanic-testing/
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/80/16/d68aa87c8bdf7a258d4658f5c10dd33ed1646cbc615f657893308261afd2/sanic-testing-23.3.0.tar.gz
+BuildArch: noarch
+
+Requires: python3-httpx
+
+%description
+# Sanic Core Test
+
+This package is meant to be the core testing utility and clients for testing Sanic applications. It is mainly derived from `sanic.testing` which has (or will be) removed from the main Sanic repository in the future.
+
+[Documentation](https://sanicframework.org/en/plugins/sanic-testing/getting-started.html)
+
+## Getting Started
+
+ pip install sanic-testing
+
+The package is meant to create an almost seemless transition. Therefore, after loading the package, it will attach itself to your Sanic instance and insert test clients.
+
+```python
+from sanic import Sanic
+from sanic_testing import TestManager
+
+sanic_app = Sanic(__name__)
+TestManager(sanic_app)
+```
+
+This will provide access to both the sync (`sanic.test_client`) and async (`sanic.asgi_client`) clients. Both of these clients are also available directly on the `TestManager` instance.
+
+## Writing a sync test
+
+Testing should be pretty much the same as when the test client was inside Sanic core. The difference is just that you need to run `TestManager`.
+
+```python
+import pytest
+
+@pytest.fixture
+def app():
+ sanic_app = Sanic(__name__)
+ TestManager(sanic_app)
+
+ @sanic_app.get("/")
+ def basic(request):
+ return response.text("foo")
+
+ return sanic_app
+
+def test_basic_test_client(app):
+ request, response = app.test_client.get("/")
+
+ assert response.body == b"foo"
+ assert response.status == 200
+```
+
+## Writing an async test
+
+Testing of an async method is best done with `pytest-asyncio` installed. Again, the following test should look familiar to anyone that has used `asgi_client` in the Sanic core package before.
+
+The main benefit of using the `asgi_client` is that it is able to reach inside your application, and execute your handlers without ever having to stand up a server or make a network call.
+
+```python
+import pytest
+
+@pytest.fixture
+def app():
+ sanic_app = Sanic(__name__)
+ TestManager(sanic_app)
+
+ @sanic_app.get("/")
+ def basic(request):
+ return response.text("foo")
+
+ return sanic_app
+
+@pytest.mark.asyncio
+async def test_basic_asgi_client(app):
+ request, response = await app.asgi_client.get("/")
+
+ assert response.body == b"foo"
+ assert response.status == 200
+```
+
+
+%package -n python3-sanic-testing
+Summary: Core testing clients for Sanic
+Provides: python-sanic-testing
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-sanic-testing
+# Sanic Core Test
+
+This package is meant to be the core testing utility and clients for testing Sanic applications. It is mainly derived from `sanic.testing` which has (or will be) removed from the main Sanic repository in the future.
+
+[Documentation](https://sanicframework.org/en/plugins/sanic-testing/getting-started.html)
+
+## Getting Started
+
+ pip install sanic-testing
+
+The package is meant to create an almost seemless transition. Therefore, after loading the package, it will attach itself to your Sanic instance and insert test clients.
+
+```python
+from sanic import Sanic
+from sanic_testing import TestManager
+
+sanic_app = Sanic(__name__)
+TestManager(sanic_app)
+```
+
+This will provide access to both the sync (`sanic.test_client`) and async (`sanic.asgi_client`) clients. Both of these clients are also available directly on the `TestManager` instance.
+
+## Writing a sync test
+
+Testing should be pretty much the same as when the test client was inside Sanic core. The difference is just that you need to run `TestManager`.
+
+```python
+import pytest
+
+@pytest.fixture
+def app():
+ sanic_app = Sanic(__name__)
+ TestManager(sanic_app)
+
+ @sanic_app.get("/")
+ def basic(request):
+ return response.text("foo")
+
+ return sanic_app
+
+def test_basic_test_client(app):
+ request, response = app.test_client.get("/")
+
+ assert response.body == b"foo"
+ assert response.status == 200
+```
+
+## Writing an async test
+
+Testing of an async method is best done with `pytest-asyncio` installed. Again, the following test should look familiar to anyone that has used `asgi_client` in the Sanic core package before.
+
+The main benefit of using the `asgi_client` is that it is able to reach inside your application, and execute your handlers without ever having to stand up a server or make a network call.
+
+```python
+import pytest
+
+@pytest.fixture
+def app():
+ sanic_app = Sanic(__name__)
+ TestManager(sanic_app)
+
+ @sanic_app.get("/")
+ def basic(request):
+ return response.text("foo")
+
+ return sanic_app
+
+@pytest.mark.asyncio
+async def test_basic_asgi_client(app):
+ request, response = await app.asgi_client.get("/")
+
+ assert response.body == b"foo"
+ assert response.status == 200
+```
+
+
+%package help
+Summary: Development documents and examples for sanic-testing
+Provides: python3-sanic-testing-doc
+%description help
+# Sanic Core Test
+
+This package is meant to be the core testing utility and clients for testing Sanic applications. It is mainly derived from `sanic.testing` which has (or will be) removed from the main Sanic repository in the future.
+
+[Documentation](https://sanicframework.org/en/plugins/sanic-testing/getting-started.html)
+
+## Getting Started
+
+ pip install sanic-testing
+
+The package is meant to create an almost seemless transition. Therefore, after loading the package, it will attach itself to your Sanic instance and insert test clients.
+
+```python
+from sanic import Sanic
+from sanic_testing import TestManager
+
+sanic_app = Sanic(__name__)
+TestManager(sanic_app)
+```
+
+This will provide access to both the sync (`sanic.test_client`) and async (`sanic.asgi_client`) clients. Both of these clients are also available directly on the `TestManager` instance.
+
+## Writing a sync test
+
+Testing should be pretty much the same as when the test client was inside Sanic core. The difference is just that you need to run `TestManager`.
+
+```python
+import pytest
+
+@pytest.fixture
+def app():
+ sanic_app = Sanic(__name__)
+ TestManager(sanic_app)
+
+ @sanic_app.get("/")
+ def basic(request):
+ return response.text("foo")
+
+ return sanic_app
+
+def test_basic_test_client(app):
+ request, response = app.test_client.get("/")
+
+ assert response.body == b"foo"
+ assert response.status == 200
+```
+
+## Writing an async test
+
+Testing of an async method is best done with `pytest-asyncio` installed. Again, the following test should look familiar to anyone that has used `asgi_client` in the Sanic core package before.
+
+The main benefit of using the `asgi_client` is that it is able to reach inside your application, and execute your handlers without ever having to stand up a server or make a network call.
+
+```python
+import pytest
+
+@pytest.fixture
+def app():
+ sanic_app = Sanic(__name__)
+ TestManager(sanic_app)
+
+ @sanic_app.get("/")
+ def basic(request):
+ return response.text("foo")
+
+ return sanic_app
+
+@pytest.mark.asyncio
+async def test_basic_asgi_client(app):
+ request, response = await app.asgi_client.get("/")
+
+ assert response.body == b"foo"
+ assert response.status == 200
+```
+
+
+%prep
+%autosetup -n sanic-testing-23.3.0
+
+%build
+%py3_build
+
+%install
+%py3_install
+install -d -m755 %{buildroot}/%{_pkgdocdir}
+if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
+if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
+if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
+if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
+pushd %{buildroot}
+if [ -d usr/lib ]; then
+ find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/lib64 ]; then
+ find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/bin ]; then
+ find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/sbin ]; then
+ find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+touch doclist.lst
+if [ -d usr/share/man ]; then
+ find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
+fi
+popd
+mv %{buildroot}/filelist.lst .
+mv %{buildroot}/doclist.lst .
+
+%files -n python3-sanic-testing -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Tue Apr 11 2023 Python_Bot <Python_Bot@openeuler.org> - 23.3.0-1
+- Package Spec generated