From ba07baa0609f6bec73f7f07ace9719b0d902272e Mon Sep 17 00:00:00 2001
From: Jan Rusnacko <jrusnack@redhat.com>
Date: Wed, 30 Oct 2013 16:06:59 +0100
Subject: [PATCH 3/4] Adding suffix module.

Suffix module contains class Suffix, whose instances represent suffixes.
---
 lib389/dsmodules/suffix.py          |   27 ++++++++++++
 tests/test_dsmodules/test_suffix.py |   77 +++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+), 0 deletions(-)
 create mode 100644 lib389/dsmodules/__init__.py
 create mode 100644 lib389/dsmodules/suffix.py
 create mode 100644 tests/test_dsmodules/test_suffix.py

diff --git a/lib389/dsmodules/__init__.py b/lib389/dsmodules/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/lib389/dsmodules/suffix.py b/lib389/dsmodules/suffix.py
new file mode 100644
index 0000000..c6ed7c6
--- /dev/null
+++ b/lib389/dsmodules/suffix.py
@@ -0,0 +1,27 @@
+
+class Suffix(object):
+
+    def __init__(self, ds, suffix_dn, backend):
+        raise NotImplementedError
+
+    def __remove__(self, ds):
+        raise NotImplementedError
+
+    def add_index(self, attr, indexTypes, *matchingRules):
+        raise NotImplementedError
+
+    def enable_supplier(self, id):
+        self.ds.repl.enable_supplier(self.dn, id)
+
+    def enable_consumer(self, id):
+        raise NotImplementedError
+
+    def enable_hub(self, id):
+        raise NotImplementedError
+
+    def enable_replica(self, id, type, flags):
+        raise NotImplementedError
+
+    def disable_replica(self):
+        raise NotImplementedError
+
diff --git a/tests/test_dsmodules/test_suffix.py b/tests/test_dsmodules/test_suffix.py
new file mode 100644
index 0000000..68851f9
--- /dev/null
+++ b/tests/test_dsmodules/test_suffix.py
@@ -0,0 +1,77 @@
+
+def test_add_remove_suffix(mock_ds):
+    # Add two suffixes and verify their backend names and dn
+    mock_ds.suffix.new("dc=example,dc=com", "userRoot")
+    assert mock_ds.suffix["dc=example,dc=com"].backend == "userRoot"
+    assert mock_ds.suffix["dc=example,dc=com"].dn == "dc=example,dc=com"
+
+    mock_ds.suffix.new("o=netscaperoot", "netscaperoot")
+    assert mock_ds.suffix["o=netscaperoot"].backend == "netscaperoot"
+    assert mock_ds.suffix["o=netscaperoot"].dn == "o=netscaperoot"
+
+    # Remove suffixes and verify they are not present in mocked DS
+    mock_ds.suffix.remove("dc=example,dc=com")
+    with pytest.raises(KeyError):
+        mock_ds.suffix["dc=example,dc=com"]
+
+    mock_ds.suffix.remove("o=netscaperoot")
+    with pytest.raises(KeyError):
+        mock_ds.suffix["o=netscaperoot"]
+
+def test_add_index(mock_ds):
+    mock_ds.suffix.new("dc=example,dc=com", "userRoot")
+    mock_ds.suffix["dc=example,dc=com"].add_index('sn', ['pres', 'eq', 'sub'])
+    assert mock_ds.dit["cn=sn,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config"]["cn"] == "sn"
+
+    # Verify that the entry has objectclass nsIndex
+    assert "nsIndex" in mock_ds.dit["cn=sn,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config"]["objectClass"]
+
+    # Verify indexTypes
+    assert "pres" in mock_ds.dit["cn=sn,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config"]["nsIndexType"]
+    assert "eq" in mock_ds.dit["cn=sn,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config"]["nsIndexType"]
+    assert "sub" in mock_ds.dit["cn=sn,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config"]["nsIndexType"]
+
+def test_enable_supplier(mock_ds):
+    mock_ds.suffix.new("dc=example,dc=com", "userRoot")
+    mock_ds.suffix["dc=example,dc=com"].enable_supplier(2)
+    assert nsds5replica in mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["objectclass"]
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicaid"] == 2
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicatype"] == 3
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5flags"] == 1
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicaroot"] == "dc=example,dc=com"
+
+def test_enable_consumer(mock_ds):
+    mock_ds.suffix.new("dc=example,dc=com", "userRoot")
+    mock_ds.suffix["dc=example,dc=com"].enable_consumer(1)
+    assert nsds5replica in mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["objectclass"]
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicaid"] == 1
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicatype"] == 2
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5flags"] == 0
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicaroot"] == "dc=example,dc=com"
+
+def test_enable_hub(mock_ds):
+    mock_ds.suffix.new("dc=example,dc=com", "userRoot")
+    mock_ds.suffix["dc=example,dc=com"].enable_hub(3)
+    assert nsds5replica in mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["objectclass"]
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicaid"] == 3
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicatype"] == 2
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5flags"] == 1
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicaroot"] == "dc=example,dc=com"
+
+def test_enable_replica(mock_ds):
+    mock_ds.suffix.new("dc=example,dc=com", "userRoot")
+    mock_ds.suffix["dc=example,dc=com"].enable_replica(2, 3, 1)
+    assert nsds5replica in mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["objectclass"]
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicaid"] == 2
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicatype"] == 3
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5flags"] == 1
+    assert mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["nsds5replicaroot"] == "dc=example,dc=com"
+
+def test_disable_replica(mock_ds):
+    mock_ds.suffix.new("dc=example,dc=com", "userRoot")
+    mock_ds.suffix["dc=example,dc=com"].enable_replica(2, 3, 1)
+    assert nsds5replica in mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]["objectclass"]
+
+    mock_ds.suffix["dc=example,dc=com"].disable_replica()
+    with pytest.raises(KeyError):
+        mock_ds.dit["cn=replica,cn=dc=example,dc=com,cn=mapping tree,cn=config"]
\ No newline at end of file
-- 
1.7.1

