test_groups.py 3.7 KB
Newer Older
1
import mcommunity
Rob Carleski's avatar
Rob Carleski committed
2
3
4
5
6
7
8
9
10

config = {
    'client_id': '1234567890',
    'secret': '123abc-456def-789ghi',
    'url_base': 'http://localhost:5000'
}


def test_group_fetch(mock_mcomm):
11
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
12
13
14
15
    conn.fetch_group('testgroup')
    assert conn.group_data['name'] == 'testgroup'


16
17
18
19
20
21
def test_group_fetch_by_cn(mock_mcomm):
    conn = mcommunity.Client(config=config)
    conn.fetch_group('alias1')
    assert conn.group_data['name'] == 'testgroup'


Rob Carleski's avatar
Rob Carleski committed
22
def test_person_fetch(mock_mcomm):
23
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
24
25
26
27
28
    person = conn.fetch_person('testuser')
    assert person['naming'] == 'testuser'


def test_group_creation(mock_mcomm):
29
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
30
31
32
    conn.create_group('testgroup')


33
34
35
36
37
def test_group_reservation(mock_mcomm):
    conn = mcommunity.Client(config=config)
    conn.reserve_group('testgroup')


Rob Carleski's avatar
Rob Carleski committed
38
def test_group_deletion(mock_mcomm):
39
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
40
41
42
43
44
    r = conn.delete_group('testgroup')
    assert r['status'] == 'success'


def test_group_renew(mock_mcomm):
45
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
46
47
48
49
50
    r = conn.renew_group('testgroup')
    assert r['status'] == 'success'


def test_group_update_aliases(mock_mcomm):
51
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
52
53
54
55
56
57
    conn.fetch_group('testgroup')
    conn.update_group_aliases('testalias')
    assert 'testalias' in conn.group_data['aliases']


def test_group_update_description(mock_mcomm):
58
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
59
60
61
62
63
64
    conn.fetch_group('testgroup')
    conn.update_group_description('test description')
    assert conn.group_data['description'] == 'test description'


def test_group_update_notice(mock_mcomm):
65
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
66
67
68
69
70
71
    conn.fetch_group('testgroup')
    conn.update_group_notice('test notice')
    assert conn.group_data['notice'] == 'test notice'


def test_group_update_links_labeled(mock_mcomm):
72
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
73
74
75
76
77
78
79
80
    conn.fetch_group('testgroup')
    links = ('Test Link', 'https://test.link')
    conn.update_group_links(links)
    assert conn.group_data['labeledUri'][0]['urlLabel'] == 'Test Link'
    assert conn.group_data['labeledUri'][0]['urlValue'] == 'https://test.link'


def test_group_update_links_plain(mock_mcomm):
81
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
82
83
84
85
86
87
88
    conn.fetch_group('testgroup')
    links = 'https://test.link'
    conn.update_group_links(links)
    assert conn.group_data['labeledUri'][0]['urlValue'] == 'https://test.link'


def test_group_owners_update(mock_mcomm):
89
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
90
91
    conn.fetch_group('testgroup')
    conn.add_group_owners('testuser2')
92
    conn.update_group_owners()
Rob Carleski's avatar
Rob Carleski committed
93
94
95
    testuser2 = conn._create_entity_ldap('testuser2')
    assert testuser2 in conn.group_data['ownerDn']
    conn.remove_group_owners('testuser2')
96
    conn.update_group_owners()
Rob Carleski's avatar
Rob Carleski committed
97
98
99
100
    assert testuser2 not in conn.group_data['ownerDn']


def test_group_members_update(mock_mcomm):
101
    conn = mcommunity.Client(config=config)
Rob Carleski's avatar
Rob Carleski committed
102
103
104
105
106
107
108
    conn.fetch_group('testgroup')
    members = [
        'testuser2',
        'testgroup2',
        'test@domain.tld'
    ]
    conn.add_group_members(members)
109
    conn.update_group_members()
Rob Carleski's avatar
Rob Carleski committed
110
111
112
113
114
115
116
    testuser2 = conn._create_entity_ldap('testuser2')
    testgroup2 = conn._create_entity_ldap('testgroup2')
    externalMember = 'test@domain.tld'
    assert testuser2 in conn.group_data['memberDn']
    assert testgroup2 in conn.group_data['memberGroupDn']
    assert conn.group_data['memberExternal'][0]['email'] == externalMember
    conn.remove_group_members(members)
117
    conn.update_group_members()
Rob Carleski's avatar
Rob Carleski committed
118
119
120
    assert testuser2 not in conn.group_data['memberDn']
    assert testgroup2 not in conn.group_data['memberGroupDn']
    assert not conn.group_data['memberExternal']