From 362b6ffc45f76651af4793b1f013d0dbd6407de3 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Thu, 12 Sep 2013 11:11:53 +0200 Subject: [PATCH] Replace old functional http.post call The patch removes a leftover of the old http helper functions and moves the check of self.conf.auth to the setUp method. Change-Id: Ie5cf3c7cfbf5dc80e9a1faf6556588d3b2284bb7 --- marconi/tests/functional/base.py | 13 +++++++++---- marconi/tests/functional/helpers.py | 23 +++++++---------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/marconi/tests/functional/base.py b/marconi/tests/functional/base.py index e1996b005..7e6423951 100644 --- a/marconi/tests/functional/base.py +++ b/marconi/tests/functional/base.py @@ -54,13 +54,18 @@ class FunctionalTestBase(testing.TestBase): self.mconf = self.load_conf(self.cfg.marconi.config).conf self.limits = self.mconf['limits:transport'] - self.header = helpers.create_marconi_headers(self.cfg) - self.headers_response_with_body = set(['location', - 'content-type']) - # NOTE(flaper87): Create client # for this test unit. self.client = http.Client() + self.header = helpers.create_marconi_headers(self.cfg) + + if self.cfg.auth.auth_on: + auth_token = helpers.get_keystone_token(self.cfg, self.client) + self.headers["X-Auth-Token"] = auth_token + + self.headers_response_with_body = set(['location', + 'content-type']) + self.client.set_headers(self.header) @classmethod diff --git a/marconi/tests/functional/helpers.py b/marconi/tests/functional/helpers.py index 23a824dd3..3badcfcf8 100644 --- a/marconi/tests/functional/helpers.py +++ b/marconi/tests/functional/helpers.py @@ -13,17 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import random import string import uuid -from marconi.tests.functional import http - -def get_keystone_token(conf): +def get_keystone_token(conf, client): """Gets Keystone Auth token.""" - req_json = { + body = { 'auth': { 'passwordCredentials': { 'username': conf.auth.username, @@ -35,14 +32,12 @@ def get_keystone_token(conf): header = {"Content-Type": "application/json", "Accept": "application/json"} - url = conf.auth.url + response = client.post(url=conf.auth.url, + headers=header, + data=body) - response = http.post(url=url, header=header, body=req_json) - response_body = json.loads(response.text) - - auth_token = response_body['access']['token']['id'] - - return auth_token + response_body = response.json() + return response_body['access']['token']['id'] def create_marconi_headers(conf): @@ -55,10 +50,6 @@ def create_marconi_headers(conf): "Client-ID": str(uuid.uuid1()) } - if conf.auth.auth_on: - auth_token = get_keystone_token(conf) - headers["X-Auth-Token"] = auth_token - return headers