Commit d969bb9a authored by John Westcott IV's avatar John Westcott IV

Fixed flake8 issues

(didn't realize tests need to adher as well)
parent 07628f95
......@@ -2,11 +2,7 @@ from tower_cli.api import client
from tower_cli.cli.transfer import common
from tower_cli.utils.data_structures import OrderedDict
from six.moves import StringIO
import sys
import click
from tests.compat import unittest, mock
from tests.compat import unittest
class TransferCommonTests(unittest.TestCase):
......@@ -14,13 +10,6 @@ class TransferCommonTests(unittest.TestCase):
in the way we expect.
"""
#def setUp(self):
# self.held, sys.stdout = sys.stdout, StringIO()
#def clear_string_buffer(self):
# sys.stdout.seek(0)
# sys.stdout.truncate(0)
def test_get_api_options(self):
# Assert that an entry without a POST section returns None
with client.test_mode as t:
......@@ -30,14 +19,14 @@ class TransferCommonTests(unittest.TestCase):
# Assert that an entry with a POST section returns the post section
with client.test_mode as t:
t.register_json('/job_templates/', {'actions': {'POST': {'test' : 'string'}}}, method='OPTIONS')
t.register_json('/job_templates/', {'actions': {'POST': {'test': 'string'}}}, method='OPTIONS')
job_template_options = common.get_api_options('job_template')
self.assertEqual(job_template_options, {'test' : 'string'}, "Failed to extract POST options")
self.assertEqual(job_template_options, {'test': 'string'}, "Failed to extract POST options")
# Test a cached API options
job_template_options = common.get_api_options('job_template')
self.assertEqual(job_template_options, {'test' : 'string'}, "Failed to extract POST options")
self.assertEqual(job_template_options, {'test': 'string'}, "Failed to extract POST options")
def test_map_node_to_post_optins(self):
def test_map_node_to_post_options(self):
source_node = {
"name": "My Name",
"created_on": "now",
......@@ -48,11 +37,11 @@ class TransferCommonTests(unittest.TestCase):
target_node = {}
post_options = {
"name" : { "required" : True},
"some_value": { "required": False, "default": "the default value" },
"name": {"required": True},
"some_value": {"required": False, "default": "the default value"},
# Note, this function does not care if a required value is missing
"some_missing_required_value" : { "required": True },
"some_other_value": { "default": "The default"},
"some_missing_required_value": {"required": True},
"some_other_value": {"default": "The default"},
}
# First test that nothing happens if post_options is None
......@@ -66,7 +55,8 @@ class TransferCommonTests(unittest.TestCase):
# # Takes an asset and loops over the defined dependences
# # These are things that may be other objects in Tower
# # For example, a credential can be tied to an Organization
# # If the user gave me an Organization like Default (which is what is expected) we need to resolve that to Defaults ID
# # If the user gave me an Organization like Default (which is what is expected) we need
# # to resolve that to Defaults ID
# def resolve_asset_dependencies(an_asset, asset_type):
# for relation in an_asset['related']:
# if relation in an_asset:
......@@ -97,19 +87,19 @@ class TransferCommonTests(unittest.TestCase):
def test_remove_encrypted_value(self):
test_hash = {
'first' : 'ok',
'second' : common.ENCRYPTED_VALUE,
'sub' : OrderedDict({
'first' : common.ENCRYPTED_VALUE,
'second' : 'ok',
'first': 'ok',
'second': common.ENCRYPTED_VALUE,
'sub': OrderedDict({
'first': common.ENCRYPTED_VALUE,
'second': 'ok',
}),
}
result_hash = {
'first' : 'ok',
'second' : '',
'sub' : {
'first' : '',
'second' : 'ok',
'first': 'ok',
'second': '',
'sub': {
'first': '',
'second': 'ok',
},
}
common.remove_encrypted_values(test_hash)
......@@ -349,14 +339,15 @@ class TransferCommonTests(unittest.TestCase):
#
# return notifications
#
def test_remove_local_path_from_scm_project(self):
asset = {
'scm_type' : 'Manual',
'local_path' : 'somewhere',
'scm_type': 'Manual',
'local_path': 'somewhere',
}
result_asset = {
'scm_type' : 'Manual',
'local_path' : 'somewhere',
'scm_type': 'Manual',
'local_path': 'somewhere',
}
# Test a no change for either Manual or '' scm_type
common.remove_local_path_from_scm_project(asset)
......
......@@ -25,14 +25,14 @@ class LoggingCommandTests(unittest.TestCase):
# Test default play recap (no starting new line)
my_logging_command.print_recap()
recap_msg = "PLAY RECAP *********************************************************************\n"+\
" ok=0 changed=0 warnings=0 failed=0\n\n"
recap_msg = "PLAY RECAP *********************************************************************\n" +\
" ok=0 changed=0 warnings=0 failed=0\n\n"
self.assertEquals(sys.stdout.getvalue(), recap_msg, "First recap message failed")
# Test second play recap (has starting new line)
self.clear_string_buffer()
my_logging_command.print_recap()
recap_msg = "\nPLAY RECAP *********************************************************************\n"+ \
recap_msg = "\nPLAY RECAP *********************************************************************\n" +\
" ok=0 changed=0 warnings=0 failed=0\n\n"
self.assertEquals(sys.stdout.getvalue(), recap_msg, "Second recap message failed")
......@@ -40,7 +40,7 @@ class LoggingCommandTests(unittest.TestCase):
self.clear_string_buffer()
my_logging_command.ok_messages = 1
my_logging_command.print_recap()
recap_msg = "\nPLAY RECAP *********************************************************************\n"+ \
recap_msg = "\nPLAY RECAP *********************************************************************\n" +\
" ok=1 changed=0 warnings=0 failed=0\n\n"
self.assertEquals(sys.stdout.getvalue(), recap_msg, "OK recap message failed")
......@@ -48,7 +48,7 @@ class LoggingCommandTests(unittest.TestCase):
self.clear_string_buffer()
my_logging_command.changed_messages = 1
my_logging_command.print_recap()
recap_msg = "\nPLAY RECAP *********************************************************************\n"+ \
recap_msg = "\nPLAY RECAP *********************************************************************\n" +\
" ok=1 changed=1 warnings=0 failed=0\n\n"
self.assertEquals(sys.stdout.getvalue(), recap_msg, "Changed recap message failed")
......@@ -56,7 +56,7 @@ class LoggingCommandTests(unittest.TestCase):
self.clear_string_buffer()
my_logging_command.warn_messages = 1
my_logging_command.print_recap()
recap_msg = "\nPLAY RECAP *********************************************************************\n"+ \
recap_msg = "\nPLAY RECAP *********************************************************************\n" +\
" ok=1 changed=1 warnings=1 failed=0\n\n"
self.assertEquals(sys.stdout.getvalue(), recap_msg, "Warn recap message failed")
......@@ -64,16 +64,16 @@ class LoggingCommandTests(unittest.TestCase):
self.clear_string_buffer()
my_logging_command.error_messages = 1
my_logging_command.print_recap()
recap_msg = "\nPLAY RECAP *********************************************************************\n"+ \
recap_msg = "\nPLAY RECAP *********************************************************************\n" +\
" ok=1 changed=1 warnings=1 failed=1\n\n"
self.assertEquals(sys.stdout.getvalue(), recap_msg, "Error recap message failed")
def test_my_print_no_color(self):
# Validate that with no_color specified a message comes out straight
my_logging_command = LoggingCommand()
my_logging_command.no_color = True
my_logging_command.my_print("Test Message", fg="red", bold="True", nl="False")
self.assertEquals(sys.stdout.getvalue(), "Test Message\n", "Message with no color did not come out correctly")
# Validate that with no_color specified a message comes out straight
my_logging_command = LoggingCommand()
my_logging_command.no_color = True
my_logging_command.my_print("Test Message", fg="red", bold="True", nl="False")
self.assertEquals(sys.stdout.getvalue(), "Test Message\n", "Message with no color did not come out correctly")
def test_print_into(self):
# Validate that the intro just prints a blank line
......@@ -83,14 +83,14 @@ class LoggingCommandTests(unittest.TestCase):
def test_get_terminal_size(self):
with mock.patch.object(click, 'get_terminal_size') as mock_method:
mock_method.return_value = [ 80, 128 ]
mock_method.return_value = [80, 128]
my_logging_command = LoggingCommand()
my_logging_command.get_rows()
self.assertEquals(my_logging_command.columns, 80, "Did not correctly get back the terminal size")
def test_print_header_row(self):
with mock.patch.object(click, 'get_terminal_size') as mock_method:
mock_method.return_value = [ 80, 128 ]
mock_method.return_value = [80, 128]
my_logging_command = LoggingCommand()
my_logging_command.print_header_row("inventory", "test inventory")
first_inv_msg = "INVENTORY [test inventory] *****************************************************\n"
......@@ -123,4 +123,3 @@ class LoggingCommandTests(unittest.TestCase):
my_logging_command.log_change("TestChange")
self.assertEquals(sys.stdout.getvalue(), "TestChange\n", "Change did not come out correctly")
self.assertEquals(my_logging_command.changed_messages, 1)
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