Browse Source

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

Tomek Mrugalski 8 years ago
parent
commit
61b0d4c3b2

+ 1 - 0
src/bin/shell/kea-shell.py

@@ -55,6 +55,7 @@ params.command = cmd_args.command
 params.http_host = cmd_args.host
 params.http_port = cmd_args.port
 params.timeout = cmd_args.timeout
+params.version = VERSION
 
 params.generateBody()
 params.generateHeaders()

+ 3 - 1
src/bin/shell/kea_conn.py

@@ -10,6 +10,7 @@
 # - command - specifies the command to send (e.g. list-commands)
 # - timeout - timeout (in ms)
 # - headers - extra HTTP headers may be added here
+# - version - version to be reported in HTTP header
 class CARequest:
     path = '/'
     http_host = ''
@@ -18,6 +19,7 @@ class CARequest:
     timeout = 0
     params = ''
     headers = {}
+    version = ""
 
     # Generates the content, out of specified command line
     # and optional content.
@@ -34,7 +36,7 @@ class CARequest:
     # In particular, this method generates Content-Length and its value.
     def generateHeaders(self):
         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['Content-Length'] = "%d"%(len(self.content))
 

+ 4 - 4
src/bin/shell/tests/Makefile.am

@@ -1,4 +1,4 @@
-PYTESTS = kea-shell_unittest.py
+PYTESTS = shell_unittest.py
 
 SHTESTS = shell_process_tests.sh
 
@@ -6,16 +6,16 @@ noinst_SCRIPTS = $(PYTESTS) shell_process_tests.sh
 EXTRA_DIST = testdata/plugins/testplugin.py
 
 # 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 \
 	echo Running python test: $$pytest ; \
 	chmod +x $(abs_builddir)/$$pytest ; \
 	PYTHONPATH=$(PYTHONPATH):$(abs_top_builddir)/src/bin/shell python $(abs_builddir)/$$pytest || exit ; \
 	done
 
-check-local-shell:
+check-shell:
 	@for shtest in $(SHTESTS) ; do \
 	echo Running shell test: $$shtest ; \
 	export KEA_LOCKFILE_DIR=$(abs_top_builddir); \

+ 9 - 0
src/bin/shell/tests/kea-shell_unittest.py

@@ -84,6 +84,15 @@ class CARequestUnitTest(unittest.TestCase):
 
         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):
         """
         This method is called after each test. Currently it does nothing.