Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from __future__ import print_function
import sys
from codecs import open
import codecs
import os

from setuptools import setup, find_packages

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
Expand Down
3 changes: 1 addition & 2 deletions tests/CLI/helper_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down
108 changes: 57 additions & 51 deletions tests/CLI/modules/call_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,73 @@
import pytest


class BuildFilterTests(testing.TestCase):
def test_filter_empty():
assert call_api._build_filters([]) == {}

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_filter_basic():
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_nested():
result = call_api._build_filters(['nested.property=value'])
assert result == {'nested': {'property': {'operation': '_= value'}}}

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_filter_multi():
result = call_api._build_filters(['prop1=value1', 'prop2=prop2'])
assert result == {
'prop1': {'operation': '_= value1'},
'prop2': {'operation': '_= prop2'},
}


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():
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():
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():
result = call_api._build_filters(['prop IN value1 , value2 '])
assert result == {
'prop': {
'operation': 'in',
'options': [{'name': 'data', 'value': ['value1', 'value2']}],
}
}


def test_filter_invalid_operation():
with pytest.raises(exceptions.CLIAbort):
call_api._build_filters(['prop N/A value1'])

def test_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():
with pytest.raises(exceptions.CLIAbort):
call_api._build_filters([' '])


class CallCliTests(testing.TestCase):
Expand Down
21 changes: 11 additions & 10 deletions tests/CLI/modules/config_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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'])
Expand All @@ -90,32 +90,33 @@ 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))

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')
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)

self.assertEqual(endpoint_url, 'custom-endpoint')

@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)

Expand Down
13 changes: 7 additions & 6 deletions tests/config_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ 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(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'])
2 changes: 1 addition & 1 deletion tests/transport_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""<member>
<name>id</name>
Expand Down