summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/api/test_middleware.py
diff options
context:
space:
mode:
authorJohn L. Villalovos <john.l.villalovos@intel.com>2015-12-04 19:27:58 -0800
committerJohn L. Villalovos <john.l.villalovos@intel.com>2015-12-06 08:25:45 -0800
commitec2a3285d85e418f1d861183c7dad75c988b2e21 (patch)
tree2f631895d64b01e2233334b97f0a04cfc47bcb01 /ironic/tests/unit/api/test_middleware.py
parente0e83b12393c4965a672ae05e608a650dac28e7d (diff)
downloadironic-ec2a3285d85e418f1d861183c7dad75c988b2e21.tar.gz
Replace HTTP 'magic numbers' with constants
Replace HTTP 'magic numbers' (also known as unnamed numerical constants) with constants provided by the http_client/httplib library. For example, use 'http_client.OK' instead of '200' This was done before in commit 107e064ca1c981480f12fad03fdd02d1f4847422 but a few more HTTP numbers have slipped in since that commit. Change-Id: Ia3db6b0c8ef832290ffde8510a7ebe33adf356c4
Diffstat (limited to 'ironic/tests/unit/api/test_middleware.py')
-rw-r--r--ironic/tests/unit/api/test_middleware.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/ironic/tests/unit/api/test_middleware.py b/ironic/tests/unit/api/test_middleware.py
index 5acd6b806..4185ccc0e 100644
--- a/ironic/tests/unit/api/test_middleware.py
+++ b/ironic/tests/unit/api/test_middleware.py
@@ -17,6 +17,7 @@ Tests to assert that various incorporated middleware works as expected.
from oslo_config import cfg
import oslo_middleware.cors as cors_middleware
+from six.moves import http_client
from ironic.tests.unit.api import base
@@ -40,6 +41,14 @@ class TestCORSMiddleware(base.BaseApiTest):
# Create the application.
super(TestCORSMiddleware, self).setUp()
+ @staticmethod
+ def _response_string(status_code):
+ """Helper function to return string in form of 'CODE DESCRIPTION'.
+
+ For example: '200 OK'
+ """
+ return '{} {}'.format(status_code, http_client.responses[status_code])
+
def test_valid_cors_options_request(self):
response = self.app \
.options('/',
@@ -49,7 +58,8 @@ class TestCORSMiddleware(base.BaseApiTest):
})
# Assert response status.
- self.assertEqual(response.status, '200 OK')
+ self.assertEqual(
+ self._response_string(http_client.OK), response.status)
self.assertIn('Access-Control-Allow-Origin', response.headers)
self.assertEqual('http://valid.example.com',
response.headers['Access-Control-Allow-Origin'])
@@ -63,7 +73,8 @@ class TestCORSMiddleware(base.BaseApiTest):
})
# Assert response status.
- self.assertEqual(response.status, '200 OK')
+ self.assertEqual(
+ self._response_string(http_client.OK), response.status)
self.assertNotIn('Access-Control-Allow-Origin', response.headers)
def test_valid_cors_get_request(self):
@@ -74,7 +85,8 @@ class TestCORSMiddleware(base.BaseApiTest):
})
# Assert response status.
- self.assertEqual(response.status, '200 OK')
+ self.assertEqual(
+ self._response_string(http_client.OK), response.status)
self.assertIn('Access-Control-Allow-Origin', response.headers)
self.assertEqual('http://valid.example.com',
response.headers['Access-Control-Allow-Origin'])
@@ -87,5 +99,6 @@ class TestCORSMiddleware(base.BaseApiTest):
})
# Assert response status.
- self.assertEqual(response.status, '200 OK')
+ self.assertEqual(
+ self._response_string(http_client.OK), response.status)
self.assertNotIn('Access-Control-Allow-Origin', response.headers)