Skip to content

Commit 02442e2

Browse files
shulutkovphlogistonjohn
authored andcommitted
tests: add OU support tests
Signed-off-by: myback <[email protected]>
1 parent 0f20155 commit 02442e2

File tree

2 files changed

+86
-43
lines changed

2 files changed

+86
-43
lines changed

tests/test_addc.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import pytest
2222

23-
2423
import sambacc.addc
2524

2625

@@ -122,6 +121,17 @@ def test_create_user(tmp_path, monkeypatch):
122121
assert "--given-name=Fred" in result
123122

124123

124+
def test_create_ou(tmp_path, monkeypatch):
125+
monkeypatch.setattr(
126+
sambacc.samba_cmds, "_GLOBAL_PREFIX", [_fake_samba_tool(tmp_path)]
127+
)
128+
129+
sambacc.addc.create_ou("quarry_workers")
130+
with open(tmp_path / "args.out") as fh:
131+
result = fh.read()
132+
assert "ou add OU=quarry_workers" in result
133+
134+
125135
def test_create_group(tmp_path, monkeypatch):
126136
monkeypatch.setattr(
127137
sambacc.samba_cmds, "_GLOBAL_PREFIX", [_fake_samba_tool(tmp_path)]

tests/test_config.py

Lines changed: 75 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
import io
2020
import os
21-
import pytest
2221
import unittest
2322

23+
import pytest
24+
2425
import sambacc.config
2526
import sambacc.opener
2627

@@ -165,7 +166,6 @@
165166
}
166167
"""
167168

168-
169169
ctdb_config1 = """
170170
{
171171
"samba-container-config": "v0",
@@ -255,6 +255,60 @@
255255
}
256256
"""
257257

258+
addc_config2 = """
259+
{
260+
"samba-container-config": "v0",
261+
"configs": {
262+
"demo": {
263+
"instance_features": ["addc"],
264+
"domain_settings": "sink",
265+
"instance_name": "dc1"
266+
}
267+
},
268+
"domain_settings": {
269+
"sink": {
270+
"realm": "DOMAIN1.SINK.TEST",
271+
"short_domain": "DOMAIN1",
272+
"admin_password": "Passw0rd"
273+
}
274+
},
275+
"organizational_units": {
276+
"sink": [
277+
{"name": "friends"}
278+
]
279+
},
280+
"domain_groups": {
281+
"sink": [
282+
{
283+
"name": "friends",
284+
"ou": "friends"
285+
},
286+
{"name": "gothamites"}
287+
]
288+
},
289+
"domain_users": {
290+
"sink": [
291+
{
292+
"name": "bwayne",
293+
"password": "1115Rose.",
294+
"given_name": "Bruce",
295+
"surname": "Wayne",
296+
"member_of": ["friends", "gothamites"],
297+
"ou": "friends"
298+
},
299+
{
300+
"name": "ckent",
301+
"password": "1115Rose.",
302+
"given_name": "Clark",
303+
"surname": "Kent",
304+
"member_of": ["friends"],
305+
"ou": "friends"
306+
}
307+
]
308+
}
309+
}
310+
"""
311+
258312

259313
class TestConfig(unittest.TestCase):
260314
def test_non_json(self):
@@ -515,6 +569,24 @@ def test_ad_dc_config_demo():
515569
assert dusers[0].username == "bwayne"
516570

517571

572+
def test_ad_dc_ou_config_demo():
573+
c1 = sambacc.config.GlobalConfig(io.StringIO(addc_config2))
574+
i1 = c1.get("demo")
575+
assert i1.with_addc
576+
577+
domou = sorted(i1.organizational_units(), key=lambda v: v.ou_name)
578+
assert len(domou) == 1
579+
assert domou[0].ou_name == "friends"
580+
581+
dgroups = sorted(i1.domain_groups(), key=lambda v: v.groupname)
582+
assert len(dgroups) == 2
583+
assert dgroups[0].ou == "friends"
584+
585+
dusers = sorted(i1.domain_users(), key=lambda v: v.username)
586+
assert len(dusers) == 2
587+
assert dusers[0].ou == "friends"
588+
589+
518590
def test_ad_dc_invalid():
519591
c1 = sambacc.config.GlobalConfig(io.StringIO(config1))
520592
i1 = c1.get("foobar")
@@ -529,47 +601,8 @@ def test_ad_dc_invalid():
529601
with pytest.raises(ValueError):
530602
list(i1.domain_groups())
531603

532-
533-
def test_ad_dc_bad_member_of():
534-
jdata = {
535-
"samba-container-config": "v0",
536-
"configs": {
537-
"demo": {
538-
"instance_features": ["addc"],
539-
"domain_settings": "sink",
540-
"instance_name": "dc1",
541-
}
542-
},
543-
"domain_settings": {
544-
"sink": {
545-
"realm": "DOMAIN1.SINK.TEST",
546-
"short_domain": "DOMAIN1",
547-
"admin_password": "Passw0rd",
548-
}
549-
},
550-
"domain_groups": {"sink": [{"name": "friends"}]},
551-
"domain_users": {
552-
"sink": [
553-
{
554-
"name": "ckent",
555-
"password": "1115Rose.",
556-
"given_name": "Clark",
557-
"surname": "Kent",
558-
"member_of": "friends",
559-
}
560-
]
561-
},
562-
}
563-
c1 = sambacc.config.GlobalConfig(initial_data=jdata)
564-
i1 = c1.get("demo")
565-
assert i1.with_addc
566-
567-
dgroups = sorted(i1.domain_groups(), key=lambda v: v.groupname)
568-
assert len(dgroups) == 1
569-
assert dgroups[0].groupname == "friends"
570-
571604
with pytest.raises(ValueError):
572-
list(i1.domain_users())
605+
list(i1.organizational_units())
573606

574607

575608
def test_share_config_no_path():

0 commit comments

Comments
 (0)