Skip to content

Commit

Permalink
Add tests for #2600
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Jan 15, 2022
1 parent e417cab commit e935866
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ docker-image:

.PHONY: test-docker-image
test-docker-image: docker-image
sudo ./tests/runner.sh
sudo --preserve-env env PATH=$$PATH ./tests/runner.sh

.PHONY: docs
docs:
Expand Down
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
51 changes: 51 additions & 0 deletions tests/test_utf8_uploads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python

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

import ssl
import unittest
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 e935866

Please sign in to comment.