def test_artifactory_api_service_should_get_ldap_configs(self):
        xml_data = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config xmlns="http://artifactory.jfrog.org/xsd/3.1.11">
    <security>
        <ldapSettings>
            <ldapSetting>
                <key>prod-ldap</key>
                <ldapUrl>ldap://ldap.forumsys.com</ldapUrl>
            </ldapSetting>
        </ldapSettings>
        <ldapGroupSettings>
             <ldapGroupSetting>
                <name>prod-ldap-group</name>
                <groupBaseDn>dc=example,dc=com</groupBaseDn>
              </ldapGroupSetting>
        </ldapGroupSettings>
    </security>
</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.ArtifactoryLdapApiService(
                self.DOMAIN, self.USERNAME, self.PASSWORD, self.LDAP_SETTING,
                self.LDAP_GROUP_SETTING, "absent")
            ldap_settings, ldap_group_settings = artifactory_api_service.get_ldap_configs(
            )

            assert ldap_settings == {"ldapSetting": self.LDAP_SETTING}
            assert ldap_group_settings == {
                "ldapGroupSetting": self.LDAP_GROUP_SETTING
            }
    def test_artifactory_api_service_should_update(self):
        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.ArtifactoryLdapApiService(
                self.DOMAIN, self.USERNAME, self.PASSWORD, self.LDAP_SETTING,
                self.LDAP_GROUP_SETTING, "present")
            result = artifactory_api_service.update()

            values['patch_entity'].assert_called_with(self.DATA)
            assert result == dict(a='b')
 def test_artifactory_api_service_should_delete_returns_true_if_state_is_present(
         self):
     ldap_settings = {'ldapSetting': self.LDAP_SETTING}
     ldap_group_settings = {'ldapGroupSetting': self.LDAP_GROUP_SETTING}
     with patch.multiple(
             artifactory_system_configuration.ArtifactoryLdapApiService,
             get_ldap_configs=DEFAULT) as values:
         values[
             'get_ldap_configs'].return_value = ldap_settings, ldap_group_settings
         artifactory_api_service = artifactory_system_configuration.ArtifactoryLdapApiService(
             self.DOMAIN, self.USERNAME, self.PASSWORD, self.LDAP_SETTING,
             self.LDAP_GROUP_SETTING, "present")
         assert not artifactory_api_service.should_delete()
 def test_artifactory_api_service_should_delete_returns_false_if_both_settings_are_none(
         self):
     ldap_settings = None
     ldap_group_settings = None
     with patch.multiple(
             artifactory_system_configuration.ArtifactoryLdapApiService,
             get_ldap_configs=DEFAULT) as values:
         values[
             'get_ldap_configs'].return_value = ldap_settings, ldap_group_settings
         artifactory_api_service = artifactory_system_configuration.ArtifactoryLdapApiService(
             self.DOMAIN, self.USERNAME, self.PASSWORD, self.LDAP_SETTING,
             self.LDAP_GROUP_SETTING, "absent")
         assert not artifactory_api_service.should_delete()
    def test_artifactory_api_service_should_delete(self):
        with patch.multiple(
                artifactory_system_configuration.ArtifactoryApiRequest,
                patch_entity=DEFAULT) as values:
            data = """security:
  ldapGroupSettings: null
  ldapSettings: null
"""
            values['patch_entity'].return_value = dict(a='b')
            artifactory_api_service = artifactory_system_configuration.ArtifactoryLdapApiService(
                self.DOMAIN, self.USERNAME, self.PASSWORD, self.LDAP_SETTING,
                self.LDAP_GROUP_SETTING, "absent")
            result = artifactory_api_service.delete()

            values['patch_entity'].assert_called_with(data)
            assert result == dict(a='b')
 def test_artifactory_api_service_should_update_returns_true_if_ldap_group_settings_are_different(
         self):
     ldap_settings = {'ldapSetting': self.LDAP_SETTING}
     ldap_group_settings = {
         'ldapGroupSetting': {
             "name": "prod-ldap-group2",
             "groupBaseDn": "dc=example,dc=com"
         }
     }
     with patch.multiple(
             artifactory_system_configuration.ArtifactoryLdapApiService,
             get_ldap_configs=DEFAULT) as values:
         values[
             'get_ldap_configs'].return_value = ldap_settings, ldap_group_settings
         artifactory_api_service = artifactory_system_configuration.ArtifactoryLdapApiService(
             self.DOMAIN, self.USERNAME, self.PASSWORD, self.LDAP_SETTING,
             self.LDAP_GROUP_SETTING, "present")
         assert artifactory_api_service.should_update()