Skip to content

Commit

Permalink
Add rests for #2600
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Jan 15, 2022
1 parent 223f927 commit 2b875b7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,5 @@ jobs:

- name: Execute tests
run: |
pip install tcms-api
make test-docker-image
11 changes: 11 additions & 0 deletions tests/test_http.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ rlJournalStart
rlAssertGrep "You are not using a secure connection." /tmp/testdata.txt
rlPhaseEnd

rlPhaseStartTest "Should allow file upload with UTF-8 filenames"
cat > ~/.tcms.conf << _EOF_
[tcms]
url = "https://$IP_ADDRESS:8443/xml-rpc/"
username = testadmin
password = password
_EOF_

rlRun -t -c "./tests/test_utf8_uploads.py -v"
rlPhaseEnd

rlPhaseStartTest "Should send ETag header"
rlRun -t -c "curl -k -D- https://$IP_ADDRESS:8443/static/images/kiwi_h20.png 2>/dev/null | grep 'ETag'"
rlPhaseEnd
Expand Down
52 changes: 52 additions & 0 deletions tests/test_utf8_uploads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python

#
# Copyright (c) 2022 Kiwi TCMS project. All rights reserved.
# Author: Alexander Todorov <[email protected]>
#

import ssl
import unittest
from datetime import datetime
from unittest.mock import patch

import requests
from tcms_api import TCMS

try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context


class DoNotVerifySSLSession(requests.sessions.Session):
def get(self, url, **kwargs):
kwargs.setdefault("verify", False)
return super().get(url, **kwargs)


class Utf8UploadTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
with patch("requests.sessions.Session") as session:
session.return_value = DoNotVerifySSLSession()
cls.rpc = TCMS().exec

def upload_and_assert(self, filename):
result = self.rpc.User.add_attachment(filename, "a2l3aXRjbXM=")
self.assertIn("url", result)
self.assertIn("filename", result)

def test_with_filename_in_french(self):
self.upload_and_assert("Screenshot_20211117-164527_Paramètres.png")

def test_with_filename_in_bulgarian(self):
self.upload_and_assert("Screenshot_2021-12-07 Плащане.png")


if __name__ == "__main__":
unittest.main()

0 comments on commit 2b875b7

Please sign in to comment.