From 54447e65547b2244ff2fa054499a3f8d25f1e876 Mon Sep 17 00:00:00 2001 From: Adam Kolar Date: Tue, 6 Aug 2024 13:49:33 +0200 Subject: [PATCH] Import CI smoke test from RHEL This is taken and edited from RHEL distgit tests/python-requests, directory Sanity/smoke. The commit hash this was copied from: 050c2979f27cc70506ddf669f9e0803a7b67c2d5 Only the necessary files were kept. Co-authored-by: Lukas Zachar --- tests/smoke/main.fmf | 6 +++++ tests/smoke/runtest.sh | 54 ++++++++++++++++++++++++++++++++++++++++++ tests/smoke/test.py | 11 +++++++++ 3 files changed, 71 insertions(+) create mode 100644 tests/smoke/main.fmf create mode 100755 tests/smoke/runtest.sh create mode 100644 tests/smoke/test.py diff --git a/tests/smoke/main.fmf b/tests/smoke/main.fmf new file mode 100644 index 0000000..b10b038 --- /dev/null +++ b/tests/smoke/main.fmf @@ -0,0 +1,6 @@ +summary: Basic sanity test for python-requests +test: ./runtest.sh +framework: beakerlib +require: + - python3-requests +duration: 5m diff --git a/tests/smoke/runtest.sh b/tests/smoke/runtest.sh new file mode 100755 index 0000000..3a28ed0 --- /dev/null +++ b/tests/smoke/runtest.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/python-requests/Sanity/smoke +# Description: Basic sanity test for python-requests module. +# Author: Adam Kolar +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing +# to use, modify, copy, or redistribute it subject to the terms +# and conditions of the GNU General Public License version 2. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGES=${PACKAGES:-"python3-requests"} + +PYTHON=${PYTHON:-"python"} +TEST="test.py" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm --all + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "cp $TEST $TmpDir" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + rlRun "$PYTHON $TEST" 0 "Running sanity test for python requests" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/smoke/test.py b/tests/smoke/test.py new file mode 100644 index 0000000..e296ef0 --- /dev/null +++ b/tests/smoke/test.py @@ -0,0 +1,11 @@ +import requests +from requests import * + +class ExceptionRequests(Exception): + pass + +if __name__=="__main__": + r=requests.get('https://redhat.com') + if r.status_code!=200 or \ + not r.text or r.encoding.lower() != 'utf-8': + raise ExceptionRequests("Sanity error")