def test_artifactory_api_service_should_get_proxy_configs_for_multiple_proxies(
            self):
        xml_data = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config xmlns="http://artifactory.jfrog.org/xsd/3.1.11">
    <proxies>
        <proxy>
            <key>defaultProxy</key>
            <host>proxy.test.com</host>
        </proxy>
        <proxy>
            <key>defaultProxy2</key>
            <host>proxy.test2.com</host>
        </proxy>
    </proxies>
</config>        
        """
        with patch.multiple(
                artifactory_system_configuration.ArtifactoryApiRequest,
                get_entity=DEFAULT) as values:
            values['get_entity'].return_value = MagicMock(content=xml_data)
            artifactory_api_service = artifactory_system_configuration.ArtifactoryProxyApiService(
                self.DOMAIN, self.USERNAME, self.PASSWORD, self.PROXIES,
                "present")
            proxies = artifactory_api_service.get_proxy_configs()
            assert proxies['proxy'] == [{
                "key": "defaultProxy",
                "host": "proxy.test.com"
            }, {
                "key": "defaultProxy2",
                "host": "proxy.test2.com"
            }]
 def test_artifactory_api_service_should_delete_returns_false_if_proxies_are_not_present(
         self):
     with patch.multiple(
             artifactory_system_configuration.ArtifactoryProxyApiService,
             get_proxy_configs=DEFAULT) as values:
         values['get_proxy_configs'].return_value = None
         artifactory_api_service = artifactory_system_configuration.ArtifactoryProxyApiService(
             self.DOMAIN, self.USERNAME, self.PASSWORD, self.PROXIES,
             "absent")
         assert not artifactory_api_service.should_delete()
    def test_artifactory_api_service_should_update_returns_true_if_proxies_are_different(
            self):
        proxies = [{"key": "defaultProxy", "host": "proxy2.test.com"}]

        with patch.multiple(
                artifactory_system_configuration.ArtifactoryProxyApiService,
                get_proxy_configs=DEFAULT) as values:
            values['get_proxy_configs'].return_value = {"proxy": self.PROXIES}
            artifactory_api_service = artifactory_system_configuration.ArtifactoryProxyApiService(
                self.DOMAIN, self.USERNAME, self.PASSWORD, proxies, "present")
            assert artifactory_api_service.should_update()
    def test_artifactory_api_service_should_delete(self):
        with patch.multiple(
                artifactory_system_configuration.ArtifactoryApiRequest,
                patch_entity=DEFAULT) as values:
            data = """proxies: null\n"""
            values['patch_entity'].return_value = dict(a='b')
            artifactory_api_service = artifactory_system_configuration.ArtifactoryProxyApiService(
                self.DOMAIN, self.USERNAME, self.PASSWORD, self.PROXIES,
                "absent")
            result = artifactory_api_service.delete()

            values['patch_entity'].assert_called_with(data)
            assert result == dict(a='b')
    def test_artifactory_api_service_should_get_proxy_configs_should_return_none(
            self):
        xml_data = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config xmlns="http://artifactory.jfrog.org/xsd/3.1.11">
    <proxies/>
</config>        
        """
        with patch.multiple(
                artifactory_system_configuration.ArtifactoryApiRequest,
                get_entity=DEFAULT) as values:
            values['get_entity'].return_value = MagicMock(content=xml_data)
            artifactory_api_service = artifactory_system_configuration.ArtifactoryProxyApiService(
                self.DOMAIN, self.USERNAME, self.PASSWORD, self.PROXIES,
                "present")
            proxies = artifactory_api_service.get_proxy_configs()

            assert proxies is None
    def test_artifactory_api_service_should_update(self):
        data = """proxies:
  defaultProxy:
    host: proxy.test.com
  defaultProxy2:
    host: proxy2.test.com
"""
        proxies = [{
            "key": "defaultProxy",
            "host": "proxy.test.com"
        }, {
            "key": "defaultProxy2",
            "host": "proxy2.test.com"
        }]
        with patch.multiple(
                artifactory_system_configuration.ArtifactoryApiRequest,
                patch_entity=DEFAULT) as values:
            values['patch_entity'].return_value = dict(a='b')
            artifactory_api_service = artifactory_system_configuration.ArtifactoryProxyApiService(
                self.DOMAIN, self.USERNAME, self.PASSWORD, proxies, "present")
            result = artifactory_api_service.update()

            values['patch_entity'].assert_called_with(data)
            assert result == dict(a='b')