Commit 61b0d4c3 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[5137] Tests rearranged, proper version is now reported in HTTP headers

parent 357a7ea3
...@@ -55,6 +55,7 @@ params.command = cmd_args.command ...@@ -55,6 +55,7 @@ params.command = cmd_args.command
params.http_host = cmd_args.host params.http_host = cmd_args.host
params.http_port = cmd_args.port params.http_port = cmd_args.port
params.timeout = cmd_args.timeout params.timeout = cmd_args.timeout
params.version = VERSION
params.generateBody() params.generateBody()
params.generateHeaders() params.generateHeaders()
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
# - command - specifies the command to send (e.g. list-commands) # - command - specifies the command to send (e.g. list-commands)
# - timeout - timeout (in ms) # - timeout - timeout (in ms)
# - headers - extra HTTP headers may be added here # - headers - extra HTTP headers may be added here
# - version - version to be reported in HTTP header
class CARequest: class CARequest:
path = '/' path = '/'
http_host = '' http_host = ''
...@@ -18,6 +19,7 @@ class CARequest: ...@@ -18,6 +19,7 @@ class CARequest:
timeout = 0 timeout = 0
params = '' params = ''
headers = {} headers = {}
version = ""
# Generates the content, out of specified command line # Generates the content, out of specified command line
# and optional content. # and optional content.
...@@ -34,7 +36,7 @@ class CARequest: ...@@ -34,7 +36,7 @@ class CARequest:
# In particular, this method generates Content-Length and its value. # In particular, this method generates Content-Length and its value.
def generateHeaders(self): def generateHeaders(self):
self.headers['Content-Type'] = 'application/json' self.headers['Content-Type'] = 'application/json'
self.headers['User-Agent'] = 'Kea-shell/0.1' self.headers['User-Agent'] = "Kea-shell/%s"%(self.version)
self.headers['Accept'] = '*/*' self.headers['Accept'] = '*/*'
self.headers['Content-Length'] = "%d"%(len(self.content)) self.headers['Content-Length'] = "%d"%(len(self.content))
......
PYTESTS = kea-shell_unittest.py PYTESTS = shell_unittest.py
SHTESTS = shell_process_tests.sh SHTESTS = shell_process_tests.sh
...@@ -6,16 +6,16 @@ noinst_SCRIPTS = $(PYTESTS) shell_process_tests.sh ...@@ -6,16 +6,16 @@ noinst_SCRIPTS = $(PYTESTS) shell_process_tests.sh
EXTRA_DIST = testdata/plugins/testplugin.py EXTRA_DIST = testdata/plugins/testplugin.py
# test using command-line arguments, so use check-local target instead of TESTS # test using command-line arguments, so use check-local target instead of TESTS
check-local: check-local-shell check-local-python check-local: check-shell check-python
check-local-python: check-python:
@for pytest in $(PYTESTS) ; do \ @for pytest in $(PYTESTS) ; do \
echo Running python test: $$pytest ; \ echo Running python test: $$pytest ; \
chmod +x $(abs_builddir)/$$pytest ; \ chmod +x $(abs_builddir)/$$pytest ; \
PYTHONPATH=$(PYTHONPATH):$(abs_top_builddir)/src/bin/shell python $(abs_builddir)/$$pytest || exit ; \ PYTHONPATH=$(PYTHONPATH):$(abs_top_builddir)/src/bin/shell python $(abs_builddir)/$$pytest || exit ; \
done done
check-local-shell: check-shell:
@for shtest in $(SHTESTS) ; do \ @for shtest in $(SHTESTS) ; do \
echo Running shell test: $$shtest ; \ echo Running shell test: $$shtest ; \
export KEA_LOCKFILE_DIR=$(abs_top_builddir); \ export KEA_LOCKFILE_DIR=$(abs_top_builddir); \
......
...@@ -84,6 +84,15 @@ class CARequestUnitTest(unittest.TestCase): ...@@ -84,6 +84,15 @@ class CARequestUnitTest(unittest.TestCase):
self.assertTrue(self.checkHeader(x.headers, 'Content-Length', str(len(x.content)))) self.assertTrue(self.checkHeader(x.headers, 'Content-Length', str(len(x.content))))
def test_headerVersion(self):
"""
This test checks if the version reported in HTTP headers is generated properly.
"""
x = CARequest()
x.version = "1.2.3"
x.generateHeaders()
self.assertTrue(self.checkHeader(x.headers, 'User-Agent', 'Kea-shell/1.2.3'))
def tearDown(self): def tearDown(self):
""" """
This method is called after each test. Currently it does nothing. This method is called after each test. Currently it does nothing.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment