def test_easily_reusable(self): """To be reusable in external tools, it should not require parameters Especially the 'arguments' parameter is a docopt-specific implementation detail and must not be mandatory. """ result = get_api_url() self.assertEqual(result, 'https://FQDN/afp-api/latest') self.mock_sanitize_host.assert_called_once_with('afp')
def test_uses_configured_servername_when_no_apiurl_defined(self): """ When servername is configured in the config, use it without running `sanitize_host` on it. """ arguments = {'--api-url': None, '--server': None} config = {'api_url': None, 'server': 'configured_stuff'} result = get_api_url(arguments, config) self.assertEqual(result, 'https://configured_stuff/afp-api/latest') self.assertEqual(self.mock_sanitize_host.call_count, 0)
def test_defaults_to_afp_url_when_nothing_defined(self): """ When nothing is configured/passed, return the default afp URL after running `sanitize_host` on it. """ arguments = {'--api-url': None, '--server': None} config = {'api_url': None, 'server': None} result = get_api_url(arguments, config) self.assertEqual(result, 'https://FQDN/afp-api/latest') self.mock_sanitize_host.assert_called_once_with('afp')
def test_returns_configured_apiurl_over_default(self): """ When an apiurl is configured, returned it without any preliminary check. """ arguments = {'--api-url': None} config = {'api_url': 'configured_stuff'} result = get_api_url(arguments, config) self.assertEqual(result, 'configured_stuff') self.mock_sanitize_host.assert_not_called()
def test_uses_servername_parameter_when_no_apiurl_defined(self): """ When servername is passed as a parameter, return it without running `sanitize_host` on it. """ arguments = {'--api-url': None, '--server': 'passed_stuff'} config = {'api_url': None, 'server': None} result = get_api_url(arguments, config) self.assertEqual(result, 'https://passed_stuff/afp-api/latest') self.assertEqual(self.mock_sanitize_host.call_count, 0)
def test_uses_configured_servername_when_no_apiurl_defined(self): """ When servername is configured in the config, returned it after running `sanitize_host` on it. """ arguments = {'--api-url': None, '--server': None} config = {'api_url': None, 'server': 'configured_stuff'} result = get_api_url(arguments, config) self.assertEqual(result, 'https://FQDN/afp-api/latest') self.mock_sanitize_host.assert_called_once_with('configured_stuff')
def test_returns_passed_apiurl_over_everything(self): """ When an apiurl is passed, return it without any preliminary check. """ arguments = {'--api-url': 'passed_stuff'} config = {'api_url': 'irrelevant_stuff'} result = get_api_url(arguments, config) self.assertEqual(result, 'passed_stuff') self.mock_sanitize_host.assert_not_called()
def test_defaults_to_afp_url_when_nothing_defined(self): """ When nothing is configured/passed, return the default afp URL after running `sanitize_host` on it. """ arguments = { '--api-url': None, '--server': None} config = { 'api_url': None, 'server': None} result = get_api_url(arguments, config) self.assertEqual(result, 'https://FQDN/afp-api/latest') self.mock_sanitize_host.assert_called_once_with('afp')
def test_uses_configured_servername_when_no_apiurl_defined(self): """ When servername is configured in the config, returned it after running `sanitize_host` on it. """ arguments = { '--api-url': None, '--server': None} config = { 'api_url': None, 'server': 'configured_stuff'} result = get_api_url(arguments, config) self.assertEqual(result, 'https://FQDN/afp-api/latest') self.mock_sanitize_host.assert_called_once_with('configured_stuff')