Skip to content

Commit

Permalink
Fix another py3 test failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kami committed Jan 8, 2018
1 parent 4512fe7 commit f7ff1ea
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions st2client/tests/unit/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import argparse
import logging

import six

from tests import base
from st2client import shell
from st2client.models.core import add_auth_token_to_kwargs_from_env
Expand All @@ -32,12 +34,20 @@

LOG = logging.getLogger(__name__)

RULE = {
'id': uuid.uuid4().hex,
'description': 'i am THE rule.',
'name': 'drule',
'pack': 'cli',
}
if six.PY3:
RULE = {
'name': 'drule',
'description': 'i am THE rule.',
'pack': 'cli',
'id': uuid.uuid4().hex
}
else:
RULE = {
'id': uuid.uuid4().hex,
'description': 'i am THE rule.',
'name': 'drule',
'pack': 'cli',
}


class TestLoginBase(base.BaseCLITestCase):
Expand All @@ -49,8 +59,6 @@ class TestLoginBase(base.BaseCLITestCase):
on duplicate code in each test class
"""

capture_output = True

DOTST2_PATH = os.path.expanduser('~/.st2/')
CONFIG_FILE = tempfile.mkstemp(suffix='st2.conf')
CONFIG_CONTENTS = """
Expand Down Expand Up @@ -269,6 +277,8 @@ def runTest(self, mock_gp):

class TestAuthToken(base.BaseCLITestCase):

capture_output = False

def __init__(self, *args, **kwargs):
super(TestAuthToken, self).__init__(*args, **kwargs)
self.parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -466,6 +476,7 @@ def test_decorate_resource_put(self):
kwargs = {'headers': {'X-Auth-Token': token}}
requests.get.assert_called_with(get_url, **kwargs)
kwargs = {'headers': {'content-type': 'application/json', 'X-Auth-Token': token}}

requests.put.assert_called_with(put_url, json.dumps(RULE), **kwargs)

# Test with token from env.
Expand All @@ -474,6 +485,9 @@ def test_decorate_resource_put(self):
self.shell.run(['rule', 'update', rule_ref, path])
kwargs = {'headers': {'X-Auth-Token': token}}
requests.get.assert_called_with(get_url, **kwargs)

# Note: We parse the payload because data might not be in the same
# order as the fixture
kwargs = {'headers': {'content-type': 'application/json', 'X-Auth-Token': token}}
requests.put.assert_called_with(put_url, json.dumps(RULE), **kwargs)
finally:
Expand Down

0 comments on commit f7ff1ea

Please sign in to comment.