From 1850183ae32704fdc158220ba4afe3150224f583 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Mon, 29 Aug 2016 22:23:42 -0500 Subject: [PATCH 1/5] Fix style issues --- setup.py | 4 +- tests/CLI/helper_tests.py | 3 +- tests/CLI/modules/call_api_tests.py | 112 ++++++++++++++-------------- tests/CLI/modules/config_tests.py | 20 ++--- tests/config_tests.py | 12 +-- 5 files changed, 74 insertions(+), 77 deletions(-) diff --git a/setup.py b/setup.py index c6b246a32..95219567a 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from __future__ import print_function import sys -from codecs import open +import codecs import os from setuptools import setup, find_packages @@ -8,7 +8,7 @@ DESCRIPTION = "A library for SoftLayer's API" if os.path.exists('README.rst'): - with open('README.rst', 'r', 'utf-8') as readme_file: + with codecs.open('README.rst', 'r', 'utf-8') as readme_file: LONG_DESCRIPTION = readme_file.read() else: LONG_DESCRIPTION = DESCRIPTION diff --git a/tests/CLI/helper_tests.py b/tests/CLI/helper_tests.py index fd0d31823..a52e9abc9 100644 --- a/tests/CLI/helper_tests.py +++ b/tests/CLI/helper_tests.py @@ -251,8 +251,7 @@ class ResolveIdTests(testing.TestCase): def test_resolve_id_one(self): resolver = lambda r: [12345] - id = helpers.resolve_id(resolver, 'test') - self.assertEqual(id, 12345) + self.assertEqual(helpers.resolve_id(resolver, 'test'), 12345) def test_resolve_id_none(self): resolver = lambda r: [] diff --git a/tests/CLI/modules/call_api_tests.py b/tests/CLI/modules/call_api_tests.py index a6ce0d767..859b302cb 100644 --- a/tests/CLI/modules/call_api_tests.py +++ b/tests/CLI/modules/call_api_tests.py @@ -13,67 +13,65 @@ import pytest -class BuildFilterTests(testing.TestCase): - - def test_empty(self): - assert call_api._build_filters([]) == {} - - def test_basic(self): - result = call_api._build_filters(['property=value']) - assert result == {'property': {'operation': '_= value'}} - - def test_nested(self): - result = call_api._build_filters(['nested.property=value']) - assert result == {'nested': {'property': {'operation': '_= value'}}} - - def test_multi(self): - result = call_api._build_filters(['prop1=value1', 'prop2=prop2']) - assert result == { - 'prop1': {'operation': '_= value1'}, - 'prop2': {'operation': '_= prop2'}, +def test_filter_empty(self): + assert call_api._build_filters([]) == {} + +def test_filter_basic(self): + result = call_api._build_filters(['property=value']) + assert result == {'property': {'operation': '_= value'}} + +def test_filter_nested(self): + result = call_api._build_filters(['nested.property=value']) + assert result == {'nested': {'property': {'operation': '_= value'}}} + +def test_filter_multi(self): + result = call_api._build_filters(['prop1=value1', 'prop2=prop2']) + assert result == { + 'prop1': {'operation': '_= value1'}, + 'prop2': {'operation': '_= prop2'}, + } + +def test_filter_in(self): + result = call_api._build_filters(['prop IN value1,value2']) + assert result == { + 'prop': { + 'operation': 'in', + 'options': [{'name': 'data', 'value': ['value1', 'value2']}], } - - def test_in(self): - result = call_api._build_filters(['prop IN value1,value2']) - assert result == { - 'prop': { - 'operation': 'in', - 'options': [{'name': 'data', 'value': ['value1', 'value2']}], - } - } - - def test_in_multi(self): - result = call_api._build_filters([ - 'prop_a IN a_val1,a_val2', - 'prop_b IN b_val1,b_val2', - ]) - assert result == { - 'prop_a': { - 'operation': 'in', - 'options': [{'name': 'data', 'value': ['a_val1', 'a_val2']}], - }, - 'prop_b': { - 'operation': 'in', - 'options': [{'name': 'data', 'value': ['b_val1', 'b_val2']}], - }, - } - - def test_in_with_whitespace(self): - result = call_api._build_filters(['prop IN value1 , value2 ']) - assert result == { - 'prop': { - 'operation': 'in', - 'options': [{'name': 'data', 'value': ['value1', 'value2']}], - } + } + +def test_filter_in_multi(self): + result = call_api._build_filters([ + 'prop_a IN a_val1,a_val2', + 'prop_b IN b_val1,b_val2', + ]) + assert result == { + 'prop_a': { + 'operation': 'in', + 'options': [{'name': 'data', 'value': ['a_val1', 'a_val2']}], + }, + 'prop_b': { + 'operation': 'in', + 'options': [{'name': 'data', 'value': ['b_val1', 'b_val2']}], + }, + } + +def test_filter_in_with_whitespace(self): + result = call_api._build_filters(['prop IN value1 , value2 ']) + assert result == { + 'prop': { + 'operation': 'in', + 'options': [{'name': 'data', 'value': ['value1', 'value2']}], } + } - def test_invalid_operation(self): - with pytest.raises(exceptions.CLIAbort): - call_api._build_filters(['prop N/A value1']) +def test_filter_invalid_operation(self): + with pytest.raises(exceptions.CLIAbort): + call_api._build_filters(['prop N/A value1']) - def test_only_whitespace(self): - with pytest.raises(exceptions.CLIAbort): - call_api._build_filters([' ']) +def test_filter_only_whitespace(self): + with pytest.raises(exceptions.CLIAbort): + call_api._build_filters([' ']) class CallCliTests(testing.TestCase): diff --git a/tests/CLI/modules/config_tests.py b/tests/CLI/modules/config_tests.py index a6f0feafd..22f6c06db 100644 --- a/tests/CLI/modules/config_tests.py +++ b/tests/CLI/modules/config_tests.py @@ -53,11 +53,11 @@ def set_up(self): @mock.patch('SoftLayer.CLI.formatting.confirm') @mock.patch('SoftLayer.CLI.environment.Environment.getpass') @mock.patch('SoftLayer.CLI.environment.Environment.input') - def test_setup(self, input, getpass, confirm_mock): + def test_setup(self, mocked_input, getpass, confirm_mock): with tempfile.NamedTemporaryFile() as config_file: confirm_mock.return_value = True getpass.return_value = 'A' * 64 - input.side_effect = ['user', 'public', 0] + mocked_input.side_effect = ['user', 'public', 0] result = self.run_command(['--config=%s' % config_file.name, 'config', 'setup']) @@ -76,11 +76,11 @@ def test_setup(self, input, getpass, confirm_mock): @mock.patch('SoftLayer.CLI.formatting.confirm') @mock.patch('SoftLayer.CLI.environment.Environment.getpass') @mock.patch('SoftLayer.CLI.environment.Environment.input') - def test_setup_cancel(self, input, getpass, confirm_mock): + def test_setup_cancel(self, mocked_input, getpass, confirm_mock): with tempfile.NamedTemporaryFile() as config_file: confirm_mock.return_value = False getpass.return_value = 'A' * 64 - input.side_effect = ['user', 'public', 0] + mocked_input.side_effect = ['user', 'public', 0] result = self.run_command(['--config=%s' % config_file.name, 'config', 'setup']) @@ -90,9 +90,9 @@ def test_setup_cancel(self, input, getpass, confirm_mock): @mock.patch('SoftLayer.CLI.environment.Environment.getpass') @mock.patch('SoftLayer.CLI.environment.Environment.input') - def test_get_user_input_private(self, input, getpass): + def test_get_user_input_private(self, mocked_input, getpass): getpass.return_value = 'A' * 64 - input.side_effect = ['user', 'private', 0] + mocked_input.side_effect = ['user', 'private', 0] username, secret, endpoint_url, timeout = ( config.get_user_input(self.env)) @@ -103,9 +103,9 @@ def test_get_user_input_private(self, input, getpass): @mock.patch('SoftLayer.CLI.environment.Environment.getpass') @mock.patch('SoftLayer.CLI.environment.Environment.input') - def test_get_user_input_custom(self, input, getpass): + def test_get_user_input_custom(self, mocked_input, getpass): getpass.return_value = 'A' * 64 - input.side_effect = ['user', 'custom', 'custom-endpoint', 0] + mocked_input.side_effect = ['user', 'custom', 'custom-endpoint', 0] _, _, endpoint_url, _ = config.get_user_input(self.env) @@ -113,9 +113,9 @@ def test_get_user_input_custom(self, input, getpass): @mock.patch('SoftLayer.CLI.environment.Environment.getpass') @mock.patch('SoftLayer.CLI.environment.Environment.input') - def test_get_user_input_default(self, input, getpass): + def test_get_user_input_default(self, mocked_input, getpass): self.env.getpass.return_value = 'A' * 64 - self.env.input.side_effect = ['user', 'public', 0] + mocked_input.side_effect = ['user', 'public', 0] _, _, endpoint_url, _ = config.get_user_input(self.env) diff --git a/tests/config_tests.py b/tests/config_tests.py index 3ef805e9f..8a623a5c3 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -86,9 +86,9 @@ def test_no_section(self, config_parser): self.assertIsNone(result) - @mock.patch('six.moves.configparser.RawConfigParser') - def test_config_file(self, config_parser): - config.get_client_settings_config_file(config_file='path/to/config') - config_parser().read.assert_called_with([mock.ANY, - mock.ANY, - 'path/to/config']) +@mock.patch('six.moves.configparser.RawConfigParser') +def test_config_file(self, config_parser): + config.get_client_settings_config_file(config_file='path/to/config') + config_parser().read.assert_called_with([mock.ANY, + mock.ANY, + 'path/to/config']) From 7f3aaa24cdb7da63309e4679b28a279707fdbad3 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Mon, 29 Aug 2016 22:26:19 -0500 Subject: [PATCH 2/5] Fix style issues --- setup.py | 1 - tests/CLI/modules/config_tests.py | 1 + tests/transport_tests.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 95219567a..eee8f4db5 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ from __future__ import print_function -import sys import codecs import os diff --git a/tests/CLI/modules/config_tests.py b/tests/CLI/modules/config_tests.py index 22f6c06db..eebf4ea2b 100644 --- a/tests/CLI/modules/config_tests.py +++ b/tests/CLI/modules/config_tests.py @@ -100,6 +100,7 @@ def test_get_user_input_private(self, mocked_input, getpass): self.assertEqual(username, 'user') self.assertEqual(secret, 'A' * 64) self.assertEqual(endpoint_url, consts.API_PRIVATE_ENDPOINT) + self.assertEqual(timeout, 0) @mock.patch('SoftLayer.CLI.environment.Environment.getpass') @mock.patch('SoftLayer.CLI.environment.Environment.input') diff --git a/tests/transport_tests.py b/tests/transport_tests.py index e3d827e1f..e262b7eb0 100644 --- a/tests/transport_tests.py +++ b/tests/transport_tests.py @@ -121,7 +121,7 @@ def test_identifier(self, request): req.identifier = 1234 self.transport(req) - args, kwargs = request.call_args + _, kwargs = request.call_args self.assertIn( """ id From 13d7743bf1dc18df4145acad9f4a967c1dfd07e6 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Mon, 29 Aug 2016 22:34:41 -0500 Subject: [PATCH 3/5] Fix style issues --- tests/CLI/modules/call_api_tests.py | 18 +++++++++--------- tests/config_tests.py | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/CLI/modules/call_api_tests.py b/tests/CLI/modules/call_api_tests.py index 859b302cb..f90664403 100644 --- a/tests/CLI/modules/call_api_tests.py +++ b/tests/CLI/modules/call_api_tests.py @@ -13,25 +13,25 @@ import pytest -def test_filter_empty(self): +def test_filter_empty(): assert call_api._build_filters([]) == {} -def test_filter_basic(self): +def test_filter_basic(): result = call_api._build_filters(['property=value']) assert result == {'property': {'operation': '_= value'}} -def test_filter_nested(self): +def test_filter_nested(): result = call_api._build_filters(['nested.property=value']) assert result == {'nested': {'property': {'operation': '_= value'}}} -def test_filter_multi(self): +def test_filter_multi(): result = call_api._build_filters(['prop1=value1', 'prop2=prop2']) assert result == { 'prop1': {'operation': '_= value1'}, 'prop2': {'operation': '_= prop2'}, } -def test_filter_in(self): +def test_filter_in(): result = call_api._build_filters(['prop IN value1,value2']) assert result == { 'prop': { @@ -40,7 +40,7 @@ def test_filter_in(self): } } -def test_filter_in_multi(self): +def test_filter_in_multi(): result = call_api._build_filters([ 'prop_a IN a_val1,a_val2', 'prop_b IN b_val1,b_val2', @@ -56,7 +56,7 @@ def test_filter_in_multi(self): }, } -def test_filter_in_with_whitespace(self): +def test_filter_in_with_whitespace(): result = call_api._build_filters(['prop IN value1 , value2 ']) assert result == { 'prop': { @@ -65,11 +65,11 @@ def test_filter_in_with_whitespace(self): } } -def test_filter_invalid_operation(self): +def test_filter_invalid_operation(): with pytest.raises(exceptions.CLIAbort): call_api._build_filters(['prop N/A value1']) -def test_filter_only_whitespace(self): +def test_filter_only_whitespace(): with pytest.raises(exceptions.CLIAbort): call_api._build_filters([' ']) diff --git a/tests/config_tests.py b/tests/config_tests.py index 8a623a5c3..0129aded4 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -87,7 +87,7 @@ def test_no_section(self, config_parser): self.assertIsNone(result) @mock.patch('six.moves.configparser.RawConfigParser') -def test_config_file(self, config_parser): +def test_config_file(config_parser): config.get_client_settings_config_file(config_file='path/to/config') config_parser().read.assert_called_with([mock.ANY, mock.ANY, From 9c80dcd0b5c46288045f0591b150b759c60a5fea Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Mon, 29 Aug 2016 22:41:40 -0500 Subject: [PATCH 4/5] Fix style issues --- tests/CLI/modules/call_api_tests.py | 9 +++++++++ tests/config_tests.py | 1 + 2 files changed, 10 insertions(+) diff --git a/tests/CLI/modules/call_api_tests.py b/tests/CLI/modules/call_api_tests.py index f90664403..80a49d018 100644 --- a/tests/CLI/modules/call_api_tests.py +++ b/tests/CLI/modules/call_api_tests.py @@ -16,14 +16,17 @@ def test_filter_empty(): assert call_api._build_filters([]) == {} + def test_filter_basic(): result = call_api._build_filters(['property=value']) assert result == {'property': {'operation': '_= value'}} + def test_filter_nested(): result = call_api._build_filters(['nested.property=value']) assert result == {'nested': {'property': {'operation': '_= value'}}} + def test_filter_multi(): result = call_api._build_filters(['prop1=value1', 'prop2=prop2']) assert result == { @@ -31,6 +34,7 @@ def test_filter_multi(): 'prop2': {'operation': '_= prop2'}, } + def test_filter_in(): result = call_api._build_filters(['prop IN value1,value2']) assert result == { @@ -40,6 +44,8 @@ def test_filter_in(): } } + + def test_filter_in_multi(): result = call_api._build_filters([ 'prop_a IN a_val1,a_val2', @@ -56,6 +62,7 @@ def test_filter_in_multi(): }, } + def test_filter_in_with_whitespace(): result = call_api._build_filters(['prop IN value1 , value2 ']) assert result == { @@ -65,10 +72,12 @@ def test_filter_in_with_whitespace(): } } + def test_filter_invalid_operation(): with pytest.raises(exceptions.CLIAbort): call_api._build_filters(['prop N/A value1']) + def test_filter_only_whitespace(): with pytest.raises(exceptions.CLIAbort): call_api._build_filters([' ']) diff --git a/tests/config_tests.py b/tests/config_tests.py index 0129aded4..ad913be57 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -86,6 +86,7 @@ def test_no_section(self, config_parser): self.assertIsNone(result) + @mock.patch('six.moves.configparser.RawConfigParser') def test_config_file(config_parser): config.get_client_settings_config_file(config_file='path/to/config') From b82119ab52ea395d5bcec2fb9b23650b6e1f492a Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Mon, 29 Aug 2016 22:52:42 -0500 Subject: [PATCH 5/5] Fix style issues --- tests/CLI/modules/call_api_tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/CLI/modules/call_api_tests.py b/tests/CLI/modules/call_api_tests.py index 80a49d018..b907d200c 100644 --- a/tests/CLI/modules/call_api_tests.py +++ b/tests/CLI/modules/call_api_tests.py @@ -45,7 +45,6 @@ def test_filter_in(): } - def test_filter_in_multi(): result = call_api._build_filters([ 'prop_a IN a_val1,a_val2',